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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
tomshaw83
Helper I
Helper I

Dax IF with Rankx

Hello everyone,

 

Complete newbie to Powerbi here, I'm wrestling with some Dax code that I hoped someone could help me with....

 

Salestable

NameStoreDepartmentGenderSales
Joe BloggsHighwaysElectricalMale$550
Sam SmithChandlerHomewareMale$400
Susan BrownHighwaysHomewareFemale$350
Jenny ShawHighwaysGardenFemale$900
Gordon MurphyChandlerElectricalMale$500

 

The first thing I wanted to do was to create a dynamic measure that changed depending on the variables (Store, Department, Gender)

 

I used the code

Staffdynamicrank = RANKX(ALLSELECTED(Salestable),CALCULATE(SUM(Salestable[Sales])),,DESC,Dense)
 
I'm not 100% sure what all the syntax means but it does seem to do what I want... The below is filtered just on store
NameStoreDepartmentGenderSalesStaffdynamicrank
Jenny ShawHighwaysGardenFemale$9001
Joe BloggsHighwaysElectricalMale$5502
Susan BrownHighwaysHomewareFemale$3503

 

However, from here it gets complicated, I want to create a bonus column for the top 4 based on the current filter chosen by the end user, so if ranked 1 bonus = $200, 2 - $150, 3 - $100, 4 - $50

 

I am trying to do something along the lines of

 

Bonus = sumx(

Salestable,

IF([Staffdynamicrank]=1,$200,0))

 

I can't get this to work just for one bonus...:(

 

I'd like to do some more complicated things, based on the amount that the staff member has earned - if they are so far ahead of the other people they get their bonus added on as well, but for now I'd just like to be able to use the IF function with the measure I have.

 

Thanks


Tom

 

 
1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @tomshaw83 , you're only an inch away from your goal of bonus calculation. You might want to try the following measure,

 

Bonus = SWITCH ( [Staffdynamicrank], 1, 200, 2, 150, 3, 100, 4, 50 )

 

Screenshot 2020-10-30 204543.png

One point worth paying attention to is your measure

Staffdynamicrank = RANKX( ALLSELECTED(Sales[Name]), ... )

is relative ranking since you might want them to be dynamic. Thus, any other measures referencing the rank measure also work in a relative manner.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Hi, @tomshaw83 , you're only an inch away from your goal of bonus calculation. You might want to try the following measure,

 

Bonus = SWITCH ( [Staffdynamicrank], 1, 200, 2, 150, 3, 100, 4, 50 )

 

Screenshot 2020-10-30 204543.png

One point worth paying attention to is your measure

Staffdynamicrank = RANKX( ALLSELECTED(Sales[Name]), ... )

is relative ranking since you might want them to be dynamic. Thus, any other measures referencing the rank measure also work in a relative manner.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Spot on!, Thanks @CNENFRNL !!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors