Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Rank decimal values using DAX

Is there a way to rank decimal values using DAX? I'm trying to rank the decimal values of the measure 'Random values' but i'm not getting the rank correctly. Measure used: Rank of random values =...
  • AlexisOlson's avatar
    4 years ago

    RANKX is hard. I'm pretty good with DAX but rarely get it right on the first try.

     

    Standard RANKX:

    RANKX ( ALL ( Table1[Name] ), [Random values],, ASC)

    The key here is iterating over distinct names rather than all of the rows of Table1. 

     

    Greg_Deckler's suggested approach is more like this:

    Rank of random values = 
    VAR CurrValue = [Random Values]
    RETURN
        COUNTROWS (
            FILTER (
                SUMMARIZE (
                    ALL ( Table1 ),
                    Table1[Name],
                    "Value", [Random Values]
                ),
                [Value] <= CurrValue
            )
        )

     

    To me, this is a bit more intuitive than either of those above:

    Rank of random values =
    RANKX (
    	SUMMARIZE ( ALL ( Table1 ), Table1[Name] ),
    	[Random Values],
    	, ASC
    )

     

  • Greg_Deckler's avatar
    4 years ago

    Anonymous I just mocked this up because I was curious. I'm wondering if the problem lies in your [Random value] measure? Because when I put the information above in a table as columns I got the right answer:

    Measure Rank of random values = RANKX( ALL(Table5),CALCULATE(SUM([Random values])),,ASC)