Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 528587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:00:09+00:00 2026-05-13T09:00:09+00:00

What is the most straightforward approach to producing a data set that can be

  • 0

What is the most straightforward approach to producing a data set that can be used in a SQL Server Reporting Services report to display the following:

SalesPerson        # Sales        # Gross        Profit
John Doe               100       $140,000       $25,000
Everyone Else (Avg.)  1200     $2,000,000      $250,000


Jane Smith              80       $100,000       $15,000
Everyone Else (Avg.)  1220     $2,040,000      $260,000


...and so on.

This is a very, very simplified example of what I’m trying to do (for instance, the real scenario involves showing the ‘Everyone Else’ broken out into three categorical rows), but it illustrates the primary objective of displaying aggregate data for each individual with a comparison to everyone else (exclusive). Pseudo-code would be fine. My first stab at the SQL code for this got pretty tangled pretty quickly, and I know there must be a more direct method.

Any tips appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:00:09+00:00Added an answer on May 13, 2026 at 9:00 am

    If you do not mind formatting later, then if we assume you have something like:

    sales_model_02

    First I’ll need some helper variables for total counts

    /* Few helper variables*/
    DECLARE @TotalQuantity int
           ,@TotalAmount decimal(19, 4)
           ,@TotalProfit decimal(19, 4)
           ,@EveryoneElse int
    

    Then we fetch total for everyone in a given period (YEAR = 2009)

    /* Fetch totals in the period*/
    SELECT  @TotalQuantity = sum(SalesQuantity)
           ,@TotalAmount = sum(SalesAmount)
           ,@TotalProfit = sum(Profit)
           ,@EveryoneElse = count(DISTINCT SalesPersonKey) - 1
    FROM   factSales AS s
           JOIN dimDate AS d ON s.DateKey = d.DateKey
    WHERE   [Year] = 2009
    
    /* Now we have totals for everyone in the period */
    

    And now for each person vs everyone else, but all in one row.

    /* Totals for each sales person vs everyone else Average */
    SELECT  FullName
           ,SUM(SalesQuantity) AS [PersonSalesCount]
           ,SUM(SalesAmount) AS [PersonSalesAmount]
           ,SUM(Profit) AS [PersonSalesProfit]
           ,( @TotalQuantity - SUM(SalesQuantity) ) / @EveryoneElse AS [EveryoneElseAvgSalesCount]
           ,( @TotalAmount - SUM(SalesAmount) ) / @EveryoneElse AS [EveryoneElseAvgSalesAmount]
           ,( @TotalProfit - SUM(Profit) ) / @EveryoneElse AS [EveryoneElseAvgSalesProfit]
    FROM    factSales AS s
            JOIN dimDate AS d ON s.DateKey = d.DateKey
            RIGHT JOIN dimSalesPerson AS p ON p.SalesPersonKey = s.SalesPersonKey
    WHERE   [Year] = 2009
    GROUP BY FullName
    

    Now you can package all this in a stored procedure with parameter(s) for date interval. May still need to tweak number of sales people to determine which were active in a certain period and how to count those who did not sell anything. With this, EveryoneElse means number of sales people who sold something -1; so if you have 10 sales people and only 5 sold something, than EveryoneElse = 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the most Rails-y way to create a table that displays data
What is the most simple and straightforward approach for serverless P2P UDP chat in
Possible Duplicate: What is the most straightforward way to pad empty dates in sql
Most apps have some kind of preferences or user settings that can be stored
What is the most straightforward way to edit some fields from a batch of
What is the most straightforward mechanism by which to link_to_remote and popout a window
Most things are dynamic in SSRS i.e you can create a custom expression for
Most objects in SAP ERP can be double clicked to get more information in
I'm trying to do something that I think should be pretty straightforward but I
It appears to me as the easiest, most straightforward solution, but please correct me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.