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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
tomshaw83
Helper I
Helper I

Dax IF with RankX (Part 2)

Hi all,


Thanks to the community for the help with my first ever query Dax IF with Rankx  

 

A recap on what was achieved in the above

 

1) A table such as the below can be dynamically ranked based on variables (gender, store, department) 

2) Based on that rank the 'bonus' appears to the top 4 sales staff (sorted below on store)

 

Salestable

NameStoreDepartmentGenderSalesStaffdynamicrankBonusNewbonus
Sarah Salmon HighwaysElectricalFemale$15001$200 
Steve BreenHighwaysFishingMale$14002$150 
Colin CodfishHighwaysElectricalMale$10003$100 
Claire PerchHighwaysGardenFemale$9004$50 
Sally SnapperHighwaysHomewareFemale$4505$0 

 

What I'm looking to achieve now is that if the top sales member for any selection, has sales greater than $200 more than their peers, then they take their bonus - Newbonus. So in the example below Sarah steals Colin's and Claire's bonus.

 

Salestable

NameStoreDepartmentGenderSalesStaffdynamicrankBonusNewbonus
Sarah Salmon HighwaysElectricalFemale$15001$200$350
Steve BreenHighwaysFishingMale$14002$150$150
Colin CodfishHighwaysElectricalMale$10003$100$0
Claire PerchHighwaysGardenFemale$9004$50$0
Sally SnapperHighwaysHomewareFemale$4505$0$0

 

I only have a very vague understanding - the below is where I have got to with a new measure...

 

Newbonus =
sumx(
Salestable,
if([Staffdynamicrank]=1
&& Salestable[Sales] ..........
 

From here I'm confused as I want to somehow to say that the difference >$200, then add that amount to the original bonus. TBH I don't know if I should be using IF or SWITCH (or another function altogether). 

 

Any help, or pointers where I can do more homework, would be greatly appreciated.

Thanks 

Tom

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @tomshaw83 , since you start the episode 2 (lucky that my reply to episode 1 got accepted as solution 😃), I'd put my solution in play. This time, it's a calculated column,

 

 

NewBonus = 
VAR __TopSales = MAXX ( Sales, Sales[Sales] )
VAR __inferior = FILTER ( Sales, __TopSales - Sales[Sales] >= 200 )
RETURN
    SWITCH (
        TRUE (),
        Sales[Sales] = __TopSales, Sales[Bonus] + SUMX ( __inferior, Sales[Bonus] ),
        Sales[Sales] > MAXX( __inferior, Sales[Sales] ), Sales[Bonus],
        0
    )

 

 

Screenshot 2020-11-02 220417.png

 

Measure solution is also available; you might want to refer to the attched file for details.

Screenshot 2020-11-03 025806.png


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
tomshaw83
Helper I
Helper I

@CNENFRNL Thank you again for your time

CNENFRNL
Community Champion
Community Champion

Hi, @tomshaw83 , since you start the episode 2 (lucky that my reply to episode 1 got accepted as solution 😃), I'd put my solution in play. This time, it's a calculated column,

 

 

NewBonus = 
VAR __TopSales = MAXX ( Sales, Sales[Sales] )
VAR __inferior = FILTER ( Sales, __TopSales - Sales[Sales] >= 200 )
RETURN
    SWITCH (
        TRUE (),
        Sales[Sales] = __TopSales, Sales[Bonus] + SUMX ( __inferior, Sales[Bonus] ),
        Sales[Sales] > MAXX( __inferior, Sales[Sales] ), Sales[Bonus],
        0
    )

 

 

Screenshot 2020-11-02 220417.png

 

Measure solution is also available; you might want to refer to the attched file for details.

Screenshot 2020-11-03 025806.png


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!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.