Forum Discussion

ebecerra's avatar
ebecerra
Microsoft Employee
4 years ago
Solved

Using a variable to determine sort order inside Rankx

I'm using a slicer to select a "Sort type" for a visualization I have. Depending on what value is selected, I am planning to use that as the sort option for a RANKX function I have. For some reason w...
  • AlexisOlson's avatar
    4 years ago

    Another option might be to flip the sign of the measure depending on Top/Bottom.

    VariableRank = 
    VAR Sgn = IF ( SELECTEDVALUE ( 'Top or Bottom'[Option] ) = "Top", 1, -1 )
    RETURN
        RANKX ( ALLSELECTED ( MyTable[pageTitle] ), Sgn * [Total PageViews] )