Forum Discussion
Anonymous
4 years agoNot applicable
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...
- 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
smpa01
Community Champion
4 years agoAnonymous 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
- Anonymous4 years agoNot applicable
Thank you for submitting a response! While the function seems to work for ranking Top 5, Top 10, and Top 20 it fails when selecting Bottom 5, Bottom 10, and Bottom 20. Thank you for this answer and it seems to be very close to what I am looking for but there seems to be an error when ranking from the "Bottom"