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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jmateu88
Helper I
Helper I

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 three fields of category and finally another with numbers which will be used to obtain a measury with the summatory.

 

PersonCountryItemAmount

MikeSpainshirts1
JohnFrancepants2
PeterItalyshoes3
JohnGreecehats4
MikeSpainbelts5
JohnFranceshirts6
SusanItalypants7
MikeSpainpants8
PeterFranceshoes9
SamGermanybelts10
MikeSpainhats1
SusanItalypants2
JohnGreeceshirts3
MikeFrancebelts4
PeterSpainshoes5
SamGermanypants6
SusanItalybelts7
MikeFrancepants8
JohnSpainhats9
SamGreecebelts10
SusanGermanyshoes1
MikeSpainshirts2
JohnFrancebelts3
SamItalyhats4
MikeGermanypants5
SusanFranceshoes6
JohnGreecebelts7
MikeSpainhats8
JohnFrancebelts9
PeterGermanypants10
SamSpainshirts1
SusanFranceshoes2

 

 

In order to be able to filter by field, I have created a parameter which allow us to choose which field use to obtain the summatory. 

However, I cannot get the ranking of these in a dynamic way. 

 

Here the parameter table created with all formulas used.

jmateu88_1-1721114123005.png

 

As we can see in the board, the dynamic ranking does not work as it woul be desired.

jmateu88_2-1721114259579.pngjmateu88_3-1721114266744.pngjmateu88_4-1721114273993.png

Is there a way to set it dynamically in order to avoid extra dax measures and have only one ranking column in the table?
Thank you in advance!

 

 

 

1 ACCEPTED SOLUTION
shafiz_p
Super User
Super User

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!!

View solution in original post

2 REPLIES 2
shafiz_p
Super User
Super User

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!!

Hello @shafiz_p and thank youv ery much  for the right answer!

The only detail to consider is that the 0 is for Country, 1 for Item and 2 for Person.

jmateu88_0-1721121786275.png

 



Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.