Forum Discussion
How to Rank a list based on 2 values? double rankX?
- 10 years ago
Hi there,
A pattern I have used in this situation is:
Final value to be ranked =
Rank on Primary Measure (ascending)
+ Rank on Secondary Measure (ascending) / (Total Row Count + 1)
The first term is the Primary Measure rank, and the second term is the Secondary Measure rank scaled to be between 0 and 1 so that it can break ties in the Primary Measure rank.
In DAX, assuming you have two measures, [Primary Measure] and [Secondary Measure], to be ranked over all rows of Table:
Final Rank = RANKX ( ALL ( Table ), RANKX ( ALL ( Table ), [Primary Measure],, ASC ) + DIVIDE ( RANKX ( ALL ( Table ), [Secondary Measure],, ASC ), ( COUNTROWS ( ALL ( Table ) ) + 1 ) ) )Just replace with your table/measure names and it should work.
Let me know how that goes :)
Hi there,
A pattern I have used in this situation is:
Final value to be ranked =
Rank on Primary Measure (ascending)
+ Rank on Secondary Measure (ascending) / (Total Row Count + 1)
The first term is the Primary Measure rank, and the second term is the Secondary Measure rank scaled to be between 0 and 1 so that it can break ties in the Primary Measure rank.
In DAX, assuming you have two measures, [Primary Measure] and [Secondary Measure], to be ranked over all rows of Table:
Final Rank =
RANKX (
ALL ( Table ),
RANKX ( ALL ( Table ), [Primary Measure],, ASC )
+ DIVIDE (
RANKX ( ALL ( Table ), [Secondary Measure],, ASC ),
( COUNTROWS ( ALL ( Table ) ) + 1 )
)
)Just replace with your table/measure names and it should work.
Let me know how that goes :)
Hello, can anyone can show how code will change for 5 columns?