PowerPivot: How to calculate the MAX of three measures?

mikebutak

New Member
Joined
Oct 18, 2012
Messages
4
Hello Community,

I'm a newbie to powerpivot/dax.

I have created three measures: 2011 sales, 2012 sales, and 2013 sales (a simple calculation, sum sales where year = 2011, etc...)

I wish to create a 4th measure: 3-Yr Max Sales, which calculates the max of 2011 Sales, 2012 Sales, and 2013 Sales. I don't see how MAX, MAXA or MAXX can be used to accomplish this. I also have tried using a long if statement, "If 2011 is greater than 2012 and 2013, etc."

Any ideas??

Thank you,
Mike
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hello Community,

I'm a newbie to powerpivot/dax.

I have created three measures: 2011 sales, 2012 sales, and 2013 sales (a simple calculation, sum sales where year = 2011, etc...)

I wish to create a 4th measure: 3-Yr Max Sales, which calculates the max of 2011 Sales, 2012 Sales, and 2013 Sales. I don't see how MAX, MAXA or MAXX can be used to accomplish this. I also have tried using a long if statement, "If 2011 is greater than 2012 and 2013, etc."

Any ideas??

Thank you,
Mike





I have discovered a very inelegant solution:

Just to review, I have 3 measures:
2011 Sales
2012 Sales
2013 Sales

I wish to create a 3-Yr Max.

I do so by a two-step process:

1. Create a fourth measure, Max of 2011 and 2012 Sales:=if([2011 Sales]>[2012 Sales],[2011 Sales],[2012 Sales])
2. Create a fifth measure, 3-Yr max Sales:=if([2013 Sales]>[Max of 2011 and 2012 Sales],[2013 Sales],[Max of 2011 and 2012 Sales])

Pretty dorky, but it gets me where I need to go.





Next question:
How to rank the results of that measure? (I could use rank in pivot table, but I'm wondering if I could create a rank measure in DAX.)

Thanks!
Mike
 
Upvote 0
You can use something like the following,

Code:
=IF(NOT(ISBLANK([Sales])),
IFERROR(
CALCULATE(
VALUES(Table2[Year]),
TOPN(
1,
VALUES(Table2[Year]),
[Sales])),
0))

The above doesn't require the 3 measures you already have but instead uses the TOPN function to pick the best selling year. It uses a single SUM(Table(Sales)) measure (shown as [Sales] above) and then you will need a Year column in either your Fact Sales or Date Dimension table, it will work with either (just replace Table2[Year] with the correct reference). The '0' is what shows when it encounters an error, which in this measure will be when it finds more than one Year with the same total. If this is likely to happen you may need a better work around but generally speaking it may be so rare that it's not worth coding for. The reason i've used a 0 is that the Year field is numerical. If it is text you can change the 0 to a text string, say "Multiple Years" (with the quotes) or you will get a type mismatch error.

This should work with any extra filtering you add as well. I can't take any credit for this as I read about it on the PowerPivotPro blog a while ago!
 
Upvote 0
You can use something like the following,

Code:
=IF(NOT(ISBLANK([Sales])),
IFERROR(
CALCULATE(
VALUES(Table2[Year]),
TOPN(
1,
VALUES(Table2[Year]),
[Sales])),
0))

The above doesn't require the 3 measures you already have but instead uses the TOPN function to pick the best selling year. It uses a single SUM(Table(Sales)) measure (shown as [Sales] above) and then you will need a Year column in either your Fact Sales or Date Dimension table, it will work with either (just replace Table2[Year] with the correct reference). The '0' is what shows when it encounters an error, which in this measure will be when it finds more than one Year with the same total. If this is likely to happen you may need a better work around but generally speaking it may be so rare that it's not worth coding for. The reason i've used a 0 is that the Year field is numerical. If it is text you can change the 0 to a text string, say "Multiple Years" (with the quotes) or you will get a type mismatch error.

This should work with any extra filtering you add as well. I can't take any credit for this as I read about it on the PowerPivotPro blog a while ago!


Wow, thanks zestyphresh! This looks like just the thing I needed.

: )
Mike
 
Upvote 0

Forum statistics

Threads
1,216,558
Messages
6,131,400
Members
449,648
Latest member
kyouryo

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