Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
AABright
Frequent Visitor

How to create a dynamic decile ranking

I am attempting to create a decile ranking which will change depending on selections.

I have a Dim table like this:

Dim Table  
IDGroupNameNumber
AV1AV1
AW2AW2
AX2AX2
AY2AY2
AZ2AZ2
BW1BW1
BX2BX2
BY3BY3

 

My Fact table is joined to the Dim on the ID field. So, for example, if selections are made where Group = A and Number = 2, my Fact table would result in this dataset, with the corresponding Score values.

Fact Table
IDScore
AW24.5
AX22.1
AY22.1
AZ21

 

 

What I need to do is arrive at a decile ranking of those IDs, across their Scores.

Step 1 would be to rank the values (There will be duplicate scores, so they can have a secondary orderby which doesn't matter. And there will be 0 and blank values).

Step 2 is to get the rate, dividing the rank be the count of all selected IDs.

Step 3 is to bucket the rates into deciles.

Fact Table  Calculations
IDScore RankRate (rank/count ID)Decile
AW24.5 411
AX22.1 30.753
AY22.1 20.55
AZ21 10.258

 

I have been researching this for a couple days now and am stuck at square one.

Thanks for your help!

1 ACCEPTED SOLUTION

@AABright So, probably something like this. PBIX is attached below signature.

Rank2 = RANK( SKIP, ALLSELECTED('Table2'), ORDERBY( CALCULATE(SUM('Table2'[Score])), DESC, CALCULATE(MAX('Table2'[Member])), DESC) )

or

Rank3 = 
    VAR __ID = MAX('Table2'[Member])
    VAR __Count = COUNTROWS( ALLSELECTED('Table2') )
    VAR __Text = CONCATENATEX( ALLSELECTED('Table2'), [Member] & "^" & [Score], "|", [Score], DESC, [Member], DESC)
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS( 
                GENERATESERIES( 1, __Count, 1 ),
                "__Value", SUBSTITUTE( PATHITEM( __Text, [Value] ), "^", "|" )
            ),
            "__ID", PATHITEM( [__Value], 1 ),
            "__Score", PATHITEM( [__Value], 2 )
        )
    VAR __Result = MAXX( FILTER( __Table, [__ID] = __ID ), [Value] )
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
AABright
Frequent Visitor

Thanks @Greg_Deckler. That second measure did create a ranking which handled the dupes. 

I didn't describe the fact table fully. The grain is at an individual (member) level which each are connected to a group ID. So when the IDs are selected from Dim_Table, Fact_Table will have multiplied rows of members belonging to those groups. And the members need to be ranked/bucketed into deciles.

Fact Table   Calculations 
IDMemberScore RankRate (rank/count ID) Decile
AW2G434F7.1 10.125 
AW2W45MW5 20.25 
AX2VKE0K4.2 40.5 

AX2

DLKD004.2 50.625 
AX2F9FN34.7 30.375 
AX26WSLF  81 
AY202LFJW02 60.75 
AZ2KOS020 70.875 

 

The second measure you suggested results in this table, starting at 104K rather than 1.

Rank 2 over all members.png

@AABright So, probably something like this. PBIX is attached below signature.

Rank2 = RANK( SKIP, ALLSELECTED('Table2'), ORDERBY( CALCULATE(SUM('Table2'[Score])), DESC, CALCULATE(MAX('Table2'[Member])), DESC) )

or

Rank3 = 
    VAR __ID = MAX('Table2'[Member])
    VAR __Count = COUNTROWS( ALLSELECTED('Table2') )
    VAR __Text = CONCATENATEX( ALLSELECTED('Table2'), [Member] & "^" & [Score], "|", [Score], DESC, [Member], DESC)
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS( 
                GENERATESERIES( 1, __Count, 1 ),
                "__Value", SUBSTITUTE( PATHITEM( __Text, [Value] ), "^", "|" )
            ),
            "__ID", PATHITEM( [__Value], 1 ),
            "__Score", PATHITEM( [__Value], 2 )
        )
    VAR __Result = MAXX( FILTER( __Table, [__ID] = __ID ), [Value] )
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@AABright Well, the first issue you are going to have is that neither Dense nor Skip will provide you with a truly unique Rank. Both will assign the same number to the duplicate values. So, to get around this you have to get a bit fancy and use what is effectively known as the Mythical DAX Index: The Mythical DAX Index Quick Measure - Microsoft Fabric Community

 

Here is an example that will return a unique rank for each ID. Note that this index is generated by first sorting by score and then by ID so AX2 will be sorted above AY2 even though they have the same score. I am assuming that you can generate the rest of the DAX for your decile.

 

Rank = 
    VAR __ID = MAX('Table'[ID])
    VAR __Count = COUNTROWS( ALLSELECTED('Table') )
    VAR __Text = CONCATENATEX( ALLSELECTED('Table'), [ID] & "^" & [Score], "|", [Score], ASC, [ID], DESC)
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS( 
                GENERATESERIES( 1, 4, 1 ),
                "__Value", SUBSTITUTE( PATHITEM( __Text, [Value] ), "^", "|" )
            ),
            "__ID", PATHITEM( [__Value], 1 ),
            "__Score", PATHITEM( [__Value], 2 )
        )
    VAR __Result = MAXX( FILTER( __Table, [__ID] = __ID ), [Value] )
RETURN
    __Result

Now, the above is verbose but it is clear what is going on and how the calculation actually works. Otherwise, if you enjoy black box magical DAX then this will also return a unique ranking with the same sorting:

Rank 2 = RANK( SKIP, ALLSELECTED('Table'), ORDERBY( CALCULATE(SUM('Table'[Score])), ASC, CALCULATE(MAX('Table'[ID])), DESC) )

Both of these are measures FYI.

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.