Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
aAmirkHan
Helper II
Helper II

Dynamic Rank Analysis Top 5 based on different measures

Hi,

In my Power BI report, I have created measures such as Revenue, Unit Sold, Total Invoice, and Operating Profit. I want to make a Rank  Analysis of States like TOP 5 states which should work based on the selection of measures.

 

Can you please advise how to achieve such a requirement?

 

aAmirkHan_0-1729573308794.png

 

Thank you

 

 

 

 

1 ACCEPTED SOLUTION

Since field value is dynamic and it changes by selection, you would not be able to sort for all. Let's say, you sort this by Unit Sold, it will sort but when change to other metric measure say revenue, sorting will change.

So to fix it, you need to use a column which is fixed. In this case Dynamic Rank could be used. See image below:

shafiz_p_0-1729659647021.png

If you don't want to show DynamicRank, you can do a little trick and formating. See image where is actually DynamicRank measure present but you would not be able to see it. 

shafiz_p_1-1729659901922.png

shafiz_p_2-1729659972811.png

This way I acheived sorting as well as maintained visual requirement.

To acheive this, just change name in the value section of DynamicRank by double clicking to single space. change font color to white. Re adjust column width.


Hope this helps!!

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

 

Best Regards,
Shahariar Hafiz

View solution in original post

6 REPLIES 6
shafiz_p
Super User
Super User

Hi @aAmirkHan  First create a field parameter. I have 2 measure revenue and avgrev. see images below:

shafiz_p_3-1729576209993.pngshafiz_p_4-1729576253235.png
Try the below code for rank dynamically:

Dynamic Rank = 
VAR _selectedMetric = SELECTEDVALUE(Metric[Metric Order])

VAR RevRank = RANKX(ALLSELECTED(Customer), [Revenue], ,DESC, DENSE)

VAR AvgRevRank = RANKX(ALLSELECTED(Customer), [AvgRev], ,DESC, DENSE)

VAR Result = 
SWITCH(
    TRUE(),
    _selectedMetric = 0, AvgRevRank,
    _selectedMetric = 1, RevRank,
    BLANK()
)

RETURN
Result

 Then create top5 measure as follows:

Top5 = IF([Dynamic Rank] <= 5, 1, BLANK())

 

Place dynamic rank measure in the table/matrix value field. Select table/matrix and go to filter pane and place top5 measure in filter this visual option. See image below:

 

shafiz_p_0-1729576008072.png

 

Desired output:

shafiz_p_1-1729576117085.pngshafiz_p_2-1729576148846.png

 

Hope this helps!!

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

 

 

Best Regards,

Shahariar Hafiz

Hi @shafiz_p ,

Thank you for the response. I tried to make it, but it is returning only rank, not value. Based on the selection metrics, I want to have dynamic value with the top 5.

Can you please suggest what should be changed or how to achieve the desired output?

 

aAmirkHan_0-1729650486690.pngaAmirkHan_1-1729650504673.png

 

Thank you

Perfect. You just forgot to place Field parameter in the matrix value section. See image below for my case:

shafiz_p_0-1729652905597.png

 

Placed the Metric Measure in the value section.

 

You can keep you slicer setting to single select or change this line to something like that. In case no measure is selected in slicer, default will be 0:

 

AR _selectedMetric = SELECTEDVALUE(Metric[Metric Order],0)

 

 

Hope this helps!!

Hi @shafiz_p ,

 

I am just one step away from achieving the desired output, but there is a sorting issue. Metric values are not coming in proper order.

It would be great if you advise on this.

 

aAmirkHan_0-1729658533343.png

However, when I try to do it sorting but later is gets changed.

 

aAmirkHan_1-1729658586798.png

 

 

Thank you

Since field value is dynamic and it changes by selection, you would not be able to sort for all. Let's say, you sort this by Unit Sold, it will sort but when change to other metric measure say revenue, sorting will change.

So to fix it, you need to use a column which is fixed. In this case Dynamic Rank could be used. See image below:

shafiz_p_0-1729659647021.png

If you don't want to show DynamicRank, you can do a little trick and formating. See image where is actually DynamicRank measure present but you would not be able to see it. 

shafiz_p_1-1729659901922.png

shafiz_p_2-1729659972811.png

This way I acheived sorting as well as maintained visual requirement.

To acheive this, just change name in the value section of DynamicRank by double clicking to single space. change font color to white. Re adjust column width.


Hope this helps!!

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

 

Best Regards,
Shahariar Hafiz

Irwan
Super User
Super User

hello @aAmirkHan 

 

is it possible to use filter pane?

Irwan_0-1729575356790.png

Irwan_1-1729575373332.png

additionally, you might want to use HASONEVALUE() if you want to show 5 top item when selecting the slicer and show all value when no slicer is selected.

Something like this,
Values = 
var _Total = CALCULATE(SUM('Table'[Value]),ALL('Table'))
Return
IF(
    HASONEVALUE('Table'[Category]),
    SUM('Table'[Value]),
    _Total
)
 
Hope this will help.
Thank you.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.