Forum Discussion

smore's avatar
smore
Icon for Advocate I rankAdvocate I
5 years ago
Solved

DAX RANKX: Rank Column that ranks based on slicer selection?

Spoiler
 

I have a slicer based on Table[Color] and a ranking measure that ranks items based on Table[Size]. When all colors are selected in the slicer it ranks every item. When a specific color is selected, it ranks only the items for that color starting from 1. This is exactly what I need. My problem using the Rank Measure is that Power BI will not let me use the Rank Measure as an axis in my visuals.

I know that I can use a calculated column as an axis for the visuals. So to work around the original problem, I tried to create a calculated column (Rank Column) that copies the Rank Measure. The calculated column works in ranking all items but when using the slicer, it does not rank items starting from 1, it just gives their overall rank based on all colors. How can I get the Calculated Column to rank starting from 1 based on the slicer selection?

Below is the DAX for the Rank Measure and Rank Column.
_____________________

Rank Measure =
RANKX(
ALLSELECTED('Table'),
CALCULATE(SUM('Table'[Size]))
,, DESC
)
______________________

 

Rank Column = 
RANKX(
         ALLSELECTED('Table'),
         CALCULATE(
                SUM('Table'[Size]),
                AllEXCEPT('Table', 'Table'[Size])
          )
          ,, DESC
)
______________________



  • Hi smore,

     

    Do you want to show the overall ranking after applying the slicer?

    Here is the output:

    Try measure as:

    Rank Measure = 
    RANKX(
        ALL('Table'),
        CALCULATE(SUM('Table'[Size]))
        ,, DESC
    )

     

    Best Regards,

    Link

     

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

     

3 Replies

  • smore ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

  • v-xulin-mstf's avatar
    v-xulin-mstf
    Icon for Community Support rankCommunity Support

    Hi smore,

     

    Do you want to show the overall ranking after applying the slicer?

    Here is the output:

    Try measure as:

    Rank Measure = 
    RANKX(
        ALL('Table'),
        CALCULATE(SUM('Table'[Size]))
        ,, DESC
    )

     

    Best Regards,

    Link

     

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.