cancel
Showing results for 
Search instead for 
Did you mean: 

Measure Ranking and Aggregations

Super User
1075 Views
Super User
Super User

Measure Ranking and Aggregations

There have been a lot of posts over the years about how to use RANKX to create a measure, but not so many about how to use RANKX to create a measure that ranks a measure. In addition, nothing really definitive on how to aggregate measures. This post is intended to fix that.

 

Essentially, a measure is created via the following formula:

 

Measure = SUM(Table1[Column2])/SUM(Table1[Column3])

A simple approach to creating a ranking of this measure does not work very well (notice that there are 2 "Two" rows:

 

 

Measure Rank (BAD) = RANKX(ALL(Table1),[Measure])

Therefore, a slightly more complex approach is required:

 

 

Measure Rank = 
VAR __current = CALCULATE(MAX([Column1]))
VAR __table = SUMMARIZE(ALL(Table1),[Column1],"__Measure",[Measure])
VAR __table1 = ADDCOLUMNS(__table,"__Rank",RANKX(__table,[__Measure]))
RETURN MAXX(FILTER(__table1,[Column1]=__current),[__Rank])

For good "measure", I have included aggregations of measures, which utilize a very similar technique:

 

 

Measure StdDev = 
VAR __table = SUMMARIZE(Table1,[Column1],"__Measure",[Measure])
RETURN STDEVX.P(__table,[__Measure]) 

 


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


aardhala Frequent Visitor
Frequent Visitor

Re: Measure Ranking and Aggregations

Very nice concept Greg. Definitely I would like to try it out. Thanks.

aardhala Frequent Visitor
Frequent Visitor

Re: Measure Ranking and Aggregations

Hi Greg, I tried this expression out and got the Dynamic Rank calculated. But I coudn't use it as a Dimension. means, I couldn't use it on axis as a Dimension of a Bar Chart. Is there any way that we use such expression to build a dynamic Dimension ?

Super User
Super User

Re: Measure Ranking and Aggregations

@aardhala - In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


Highlighted
alissa Frequent Visitor
Frequent Visitor

Re: Measure Ranking and Aggregations

This is awesome, and so streamlined! Could one use similar code to calculate a percentile (like PERCENTRANK in Excel)? What would that look like? I've been trying to implement something like this with DAX and it's becoming way too memory intensive.