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
kimalto452
Frequent Visitor

RANKX duplicated values, showing only 1 or showing duplicate ranking

hi, I'm new with power bi . How I can do ranking for sum price of orders.

I have table "orders" which have column "product" and "price" , the product column have duplicated values with diferent price, I need sum all price by product and then rank them.

ProductTotal ChargeRank
ProdAAA1501
ProdBBB1002
ProdCCC803

 

Rank = RANKX(ALL(orders), SUMX(orders,orders[price])) 
with this measure I recive all 1
 
with this code I recive duplicated rank for diferent price
Rank = RANKX( ALL(orders), CALCULATE(SUMX(orders,orders[price])))
for example
ProdAA1501
ProdBB1301
ProdCC1203
  

 

Thanks!!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@kimalto452 ,

if it's a column range

Rank á RANKX(ALL(orders), orders[price],,desc,dense)

if it's a range of measurement
Treat
Total charge : SUM(orders[price]) // or similar formula

Then

Range Measurement -Range - RANKX(ALL(orders[Product]), [Total Charge],,desc,dense)
Or
Range Measurement -Range - RANKX(ALL(orders[Product]), [Total Charge],,desc,dense) + rand()/1000

For range See these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

What result do you get with these measures?

Total price = SUM(Orders[Price])

Rank = rankx(all(Orders[product]),[Total price])


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@kimalto452 ,

if it's a column range

Rank á RANKX(ALL(orders), orders[price],,desc,dense)

if it's a range of measurement
Treat
Total charge : SUM(orders[price]) // or similar formula

Then

Range Measurement -Range - RANKX(ALL(orders[Product]), [Total Charge],,desc,dense)
Or
Range Measurement -Range - RANKX(ALL(orders[Product]), [Total Charge],,desc,dense) + rand()/1000

For range See these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

Total Charge = SUM(orders[price]) 

then

Rank Measure = RANKX(ALL(orders[Product]), [Total Charge],,desc,dense)

 

its works !! thanks !  

can you explain please why I need use orders[Product] in ALL function ? because whe I put only table name ALL(orders) its dosen't works...

Hi,

You are welcome.  You must use ALL(Orders[Product]) because you have dragged Product to your visual.

If my previous reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

@kimalto452 - You can use RAND() to break ties:

Rank = RANKX( ALL(orders),SUMX(orders,orders[price])*(RAND()/100))

 

Also, you don't need CALCULATE there.

 

This might also help - https://community.powerbi.com/t5/Quick-Measures-Gallery/To-Bleep-with-RANKX/m-p/1042520#M452

 

Finally there is also this: https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Mythical-DAX-Index/m-p/1093214#M528

 


@ 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...

9dea4195701980116fedecc4f280cbe4

this dosen't work

Rank = RANKX( ALL(orders),SUMX(orders,orders[price])*(RAND()/100))

 

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.