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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
DataSkills
Resolver I
Resolver I

Rankx should be easy! Why doesn't this work?

I am attempting to create the simplest of Rank measures! I have a single table (SalesData) of data, with a column called "Cost of Sales". 

I want to create a basic rankx function which ranks a dimension by the Cost of Sales. Sounds simple! But I cannot get this to show a result other than 1 every time no matter how I write this DAX.  Any suggestions? I am sure it's something daft!

 

DataSkills_0-1729076815042.png

 

COS Rank =
//Attempt 1
//rankx(SalesTable, sum(SalesTable[Cost of sales]))

//Attempt 2
//rankx(all(SalesTable), sum(SalesTable[Cost of sales]))

//Attempt 3
//rankx(all(SalesTable), CALCULATE(sum(SalesTable[Cost of sales])))

//Attempt 4
//rankx(SalesTable, CALCULATE(sum(SalesTable[Cost of sales])))

//Attempt 5
//rankx(SalesTable, [COS Measure])

//Attempt 6
//rankx(all(SalesTable), [COS Measure])

//Attempt 7
//rankx(all(SalesTable), [COS Measure])

//Attempt 8
rankx(SalesTable, CALCULATE([COS Measure]))

 

You can download a sample here

 

Just click on the download link at top right to download the PBIX. 

DataSkills_1-1729077112969.png

 

Thanks!

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hello, 

You were on the right track by using ALL. The only issue now is that since you remove all filters the values are same for all rows so every row returns one. By adding a column reference  the calculation should work. E.g. all(SalesTable[Region])

I recommend checking this article by SQLBI: Introducing RANKX in DAX - SQLBI

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataSkills
Resolver I
Resolver I

Whilst @ValtteriN solution works, I am still a bit confused about this. Reviewing several articles about this function, the implication is you can simply use a format like RANKX(SalesTable, [COS Measure]). 

 

Eg https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

 

In this article it states: 

RANKX(
‘Sales Table’,
‘Sales Table'[Total Sales]
)
 
But this doesn't work in my case. 
DataSkills
Resolver I
Resolver I

 Thank you @ValtteriN . 

So this was the solution:

rankx(all(SalesTable[Region]), CALCULATE(sum(SalesTable[Cost of sales])))
 
or using the measure:
rankx(all(SalesTable[Region]), [COS Measure])
ValtteriN
Super User
Super User

Hello, 

You were on the right track by using ALL. The only issue now is that since you remove all filters the values are same for all rows so every row returns one. By adding a column reference  the calculation should work. E.g. all(SalesTable[Region])

I recommend checking this article by SQLBI: Introducing RANKX in DAX - SQLBI

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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