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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Kunder
Frequent Visitor

RANX returns same ranking for two different values

This is my table 

Customer     Sales
A6
B13
D5
E7
R8
G2
A9

 

This is what I get from the DAX below :

=RANKX(ALL(Sheet1),Sheet1[Totalsales])

where [Totalsales] is another measure with the calculation =SUM(Sheet1[Sales])

Kunder_0-1641547138428.png

Why duplicates here? please help

2 ACCEPTED SOLUTIONS
raimon
Resolver II
Resolver II

Hi @Kunder ,

If you are creating a measure for Rank, please use this - 

Rank Measure = RANKX(ALL('Table'[Customer]),CALCULATE(SUM('Table'[Sales])),,DESC)
raimon_0-1641558662500.png

 

 
Else, if you want to create a column, first need to create another column for total sales. 
Total Sales = CALCULATE(SUM('Table'[Sales]),FILTER('Table','Table'[Customer]=EARLIER('Table'[Customer])))
Rank Column = RANKX('Table','Table'[Total Sales],,desc)
 raimon_1-1641558670404.png

 

 

View solution in original post

Thejeswar
Community Champion
Community Champion

@Kunder ,

Yes !! If you want to avoid using Calculate, you may try to use a separate measure, where you get the sales values. Then use it inside the RANKX function.

 

The Below post might give you more info on this

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

 

View solution in original post

9 REPLIES 9
Viswanathan123
New Member

i have 4 columns named customername, department, country and profit. i am trying to rank based on profit it is giving me unique ranks for the whole table . What i need help with is if i am filtering a department named finance it contains 20 rows i need the ranks to be created new for that department based on the profit not the ranks from the whole table for the filtered department alone i need the ranks to start from begining any suggestions for that.
can we use RANKX inside another RANKX?

 

Hi @Viswanathan123 ,

If you are using the ALL() function, the RANK will not be recalculated for the slicer selection. Instead use the below DAX using ALLSELECTED() DAX function

Rank = RANKX(ALLSELECTED('Table'), [TotalProfit],,DESC,Dense)
Before applying filter on department
Thejeswar_1-1697095446867.png

 

 
After applying filter on department
Thejeswar_0-1697095381449.png

 

Regards,

raimon
Resolver II
Resolver II

Hi @Kunder ,

If you are creating a measure for Rank, please use this - 

Rank Measure = RANKX(ALL('Table'[Customer]),CALCULATE(SUM('Table'[Sales])),,DESC)
raimon_0-1641558662500.png

 

 
Else, if you want to create a column, first need to create another column for total sales. 
Total Sales = CALCULATE(SUM('Table'[Sales]),FILTER('Table','Table'[Customer]=EARLIER('Table'[Customer])))
Rank Column = RANKX('Table','Table'[Total Sales],,desc)
 raimon_1-1641558670404.png

 

 
Thejeswar
Community Champion
Community Champion

Hi @Kunder ,

You need to modify your RANKX as follows

 

 

RankMeasure = RANKX(ALL('Table'[Customer]), CALCULATE(SUM('Table'[Sales])),,DESC)

 

. Here RANKX is written inside a calculated Measure

Thejeswar_0-1641552038785.png

If you don't want to see the Rank in Total row, use the below DAX

RankMeasure = IF(HASONEFILTER('Table'[Customer]), RANKX(ALL('Table'[Customer]), CALCULATE(SUM('Table'[Sales])),,DESC))

 

 

@Thejeswar - This worked. One last thing. Is CALCULATE mandatory here? and why?

Thejeswar
Community Champion
Community Champion

@Kunder ,

Yes !! If you want to avoid using Calculate, you may try to use a separate measure, where you get the sales values. Then use it inside the RANKX function.

 

The Below post might give you more info on this

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

 

SanketBhagwat
Solution Sage
Solution Sage

Hi @Kunder .
Try the below DAX;
Rank=RANKX(Table,Table[TotalSales],,DESC)

Thanks,
Sanket.


If this post helps you, then please mark it as 'Accept as Solution' and give it a thumbs up.

@SanketBhagwat  -I get '1' for all ranks

 

Kunder_0-1641548764176.png

SanketBhagwat_0-1641550505215.png

Can you try this measure,

Rank = RANKX(ALL('Table1'), CALCULATE(SUM(Table1[TotalSales])),,DESC)

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.