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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

[DAX] Why doesn't my Rankx measure work?

Hello guys, 

Please I need your help for my dax formula.

I have a dataset composed of 10 categories and different products for each of these categories ( products in one category can't be found in another category ) 

I want to measure the products that costed the least to produce each year. I have created this measure to compute the evolution YoY: 

YoY% = divide ( sum(cost_current_year) - sum(cost_last_year),sum(cost_last_year))) and formatted it to %.

Then I created this measure to rank them :  rank = rankx(ALLSELECTED(Table[Products]),[YoY(%)],,ASC)

 

My problem : I want to only show the TOP 1 ( best evolution ) product for each of the categories. So I filter by my measure rank ( rank=1 )

But in my matrix or table, it displays sometimes one product sometimes two or three that are ranked 1 for the same category although i filtered with rank=1 and they have different YoY% values  ? where is my mistake i just can't find it ..  I only want to show one product for each category.

 

Note that I have only one dataset and it's not a problem of relations.

 

Thanks for trying to understand my problem

 

 

 

 

1 REPLY 1
Greg_Deckler
Super User
Super User

@Anonymous RANKX by default returns duplicate rankings if the expression is the same. There's no real way around it other than perhaps adding very small random numbers to your expression to ensure that they are each unique. 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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