March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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])
eyJrIjoiNDU2MWI3YTUtZWIxZi00MDQ0LTgzNDAtNDA5NWUxM2YyODQwIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9
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.
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 ?
@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...
Very nice concept Greg. Definitely I would like to try it out. Thanks.