DAX Calculation To Bucket Aggregate Variances

Hopeless Cub Fan

New Member
Joined
May 25, 2011
Messages
31
I am trying to create aggregate positive and negative variance buckets based on my Power Pivot dataset. The basic steps I am trying to achieve are below:

  • Step 1: Calculate a variance at an aggregate level, in this example “Group
  • Step 2: Look at the variance associated with each group and place it into either a “Positive” or “Negative” variance bucket
  • Step 3: Be able to have all the associated variance roll up under either the “Positive” or “Negative” bucket
The table below provides a very basic outline of what I want.

I am sure this isn't very difficult, but I've already spend 6+ hours trying to get it on my own. Thanks in advance for any help you can offer!

Excel 2010
ABCDEFGHIJ
1Step 1: Base DataStep 2: SortedStep 3: Desired Result
2GroupVarianceVariance GroupingVariance GroupingGroupVarianceVariance GroupingVariance
3A-10NegativePositiveE42Positive81
4B25PositivePositiveB25Negative-23
5C3PositivePositiveI10Total58
6D-3NegativePositiveC3
7E42PositivePositiveF1
8F1PositivePositiveG0
9G0PositiveNegativeD-3
10H-10NegativeNegativeA-10
11I10PositiveNegativeH-10
12Total58
13
14* Groups above are aggregations of detailed data

<tbody>
</tbody>
Sheet1
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
YTD Sales Var = 2015 YTD Sales - 2014 YTD Sales

I use a slicer to pull the relevant YTD months into the pivot.

2014 YTD Sales: =CALCULATE(SUM(Table1[SALES]),Table1[YEAR]=2014)
2015 YTD Sales: =CALCULATE(SUM(Table1[SALES]),Table1[YEAR]=2015)
YTD Sales Var: =Table1[2015 YTD Sales]-Table1[2014 YTD Sales]

Below is a rank measure I created that is properly ranking the YTD year over year variances.

Rank By Product Group:
=if(
CALCULATE(SUM(Table1[SALES]),Table1[YEAR]=2015,FILTER(Table1,Table1[PERIOD]=3))=0,
0,
calculate(RANKX(FILTER(All(Table1[PRDGRPDESC]),Table1[YTD Sales Var]),Table1[YTD Sales Var],,,Dense),Table1[YEAR]=2015))
 
Upvote 0
You so crazy :)

I would really love for you to have a real calendar table, and not write measures specifically to a year (eg 2014). If you had a calendar/date table you could just use Sales YTD := CALCULATE(SUM(Table1[Sales]), DATESYTD(Dates[DateKey])) and such (that would work for any year...)

I don't have a SUPER strong feeling for writing a "Positive" and "Negative" measure here... vs a calculated column on the group table. The latter is certainly easier AND let's you slice the groups to just show 1 or the other. But using a measure makes it more dynamic. So, depends on your goals I guess.

Any thoughts on which way you are heading?
 
Upvote 0
I am indeed crazy. :cool:

Ridiculous question, but what would a calendar table entail? My detailed data contains a month and year time dimension. Still kinda new to Power Pivot, so definitely interested in best practices. I haven't used any DAX time functions yet.

For the positive/negative piece, I would be interested in how I could do the groupings both using a measure and a calculated column. I'm guessing creating a calculated column is probably the preferred solution for the desired output below, which has evolved slightly to segment both the negative and positive variances via "Top X" and "All Other" buckets:

2014 YTD Sales2015 YTD SalesYTD Sales Var2014 YTD Qty2015 YTD QtyYTD Qty Var
Top 10 Positive Variances
All Other Positive Variances

<tbody>
</tbody>

Top 10 Negative Variances
All Other Negative Variances

In this situation above variances are ranked based on the "YTD Sales Var" field, largest positive variance = top. Thanks for the help!
 
Last edited:
Upvote 0
Your month and year table is the basis of such a date table, but it should contain EVERY date between your first possible and last envisaged date. You will have columns for Calendar year (of that date), Month Number, Month Name, maybe Calendar Quarter, maybe Fiscal Year and Quarter, and any other columns that you might feel useful. That table would be loaded into Power Pivot and marked as a date table (there is a ribbon function to do this). Link the date/calendar table to your fact table by the date. The world of time intelligence (such as the measure Scott mentioned) is available to you.

There is one on Azure that you can just plug into The Ultimate Date Table - PowerPivotPro PowerPivotPro, or you could create it in Excel or Power Query, or write some SQL to create one.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top