Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Ranking a measure within a Matrix

Hello Power BI Community,   I am unable to come up with a way to rank individual products within a Matrix. Whenever I try and use RANKX or similar functions the rank is always 1 for all rows. The d...
  • smpa01's avatar
    4 years ago

    Anonymous  you can write a measure like this; pbix is attached

    Ranking = 
    VAR _AscendingOrder =
        RANKX ( ALLSELECTED ( 'Order Report'[Product Name] ), [_revenue],, ASC )
    VAR _DescendingOrder =
        RANKX ( ALLSELECTED ( 'Order Report'[Product Name] ), [_revenue],, DESC )
    VAR _selection =
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( 'New-Slicer'[Category] ) = "Bottom10"
                || SELECTEDVALUE ( 'New-Slicer'[Category] ) = "Bottom20"
                || SELECTEDVALUE ( 'New-Slicer'[Category] ) = "Bottom5", _AscendingOrder,
            _DescendingOrder
        )
    VAR _value =
        IF ( _selection <= SELECTEDVALUE ( 'New-Slicer'[Value] ), _selection )
    RETURN
       _value