Forum Discussion

jmateu88's avatar
jmateu88
Helper I
2 years ago
Solved

Dynamic ranking by different fields

Hello,   I am trying to get the ranking of a sum by choosing the field but unfortunately, I do not know how to create a dynamic ranking dax.   Here I attach the data. As we can see, there are thr...
  • shafiz_p's avatar
    2 years ago

    Hi, jmateu88 Please use the below measure, which dynamically rank different fields.

    Rank =

    VAR _selectedValue = SELECTEDVALUE(Parameter[Parameter Order])

    VAR _rankCountry = RANKX(ALLSELECTED('Table'[Country]), [TotalAmount])
    VAR _rankItem = RANKX(ALLSELECTED('Table'[Item]), [TotalAmount])
    VAR _rankPerson = RANKX(ALLSELECTED('Table'[Person]), [TotalAmount])

    VAR _Result =
    SWITCH(
        TRUE(),
        _selectedValue=0, _rankItem,
        _selectedValue=1, _rankPerson,
        _rankCountry
    )

    RETURN
    _Result

    Hope this helps!!

    If this solved your problem, please accept it as a solution!!