This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
Your file has been submitted successfully. We’re processing it now - please check back in a few minutes to view your report.
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.