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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ngct1112
Post Patron
Post Patron

RANKX base on other columns

Hi all, I am trying to rank (from lowest to highest) a column as below

1.) Ranking of Products(ASC): Ranking the "Products" from highest to lowest

This is working -

 

Ranking of Products(ASC)= RANKX( ALLSELECTED(Table),CALCULATE(SUM('Table'[Products])))

 

2.)Ranking of cost(DESC): Ranking the "cost" only when "Ranking of Products(ASC)" = 1

This is not working -

 

Ranking of cost(DESC) = IF([Ranking of Products(ASC)]=1,RANKX( ALLSELECTED(Table),CALCULATE(SUM('Table'[cost])),,ASC))

 

ItemsProductsLowest Cost
A512
B58
C55
D44
E27

 

Desired Outcome:

 

ItemsProductsCost Ranking of Products(ASC)Ranking of cost(DESC)
A512 13
B58 12
C55 11
D44 3 
E27 2 

 

Could I have some advices on the second measure? Great thanks!

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@ngct1112 , Try like

 

new Rank = RANKX( filter(ALLSELECTED(Table[Items],Table[Products]), Table[Products] =max(Table[Products])), CALCULATE(SUM('Table'[cost])),,ASC)

 

Ranking of cost(DESC) = IF([Ranking of Products(ASC)]=1,[new Rank ], blank())

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

v-xicai
Community Support
Community Support

Hi @ngct1112 ,

 

For the logical of DESC order and ASC order, it may be wrong in the original post. And I have correct it in the following formulas .

 

You may create measures like DAX below.

 

 

 

Ranking of Products(DESC) = RANKX( ALLSELECTED('Table'),CALCULATE(SUM('Table'[Products])), ,DESC,Dense)


Ranking of cost(ASC) = IF('Table'[Ranking of Products(DESC)]=1, RANKX( FILTER(ALLSELECTED('Table'), 'Table'[Ranking of Products(DESC)]=1),CALCULATE(SUM('Table'[cost])),,ASC,Dense))

 

 

 

205.png

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xicai
Community Support
Community Support

Hi @ngct1112 ,

 

For the logical of DESC order and ASC order, it may be wrong in the original post. And I have correct it in the following formulas .

 

You may create measures like DAX below.

 

 

 

Ranking of Products(DESC) = RANKX( ALLSELECTED('Table'),CALCULATE(SUM('Table'[Products])), ,DESC,Dense)


Ranking of cost(ASC) = IF('Table'[Ranking of Products(DESC)]=1, RANKX( FILTER(ALLSELECTED('Table'), 'Table'[Ranking of Products(DESC)]=1),CALCULATE(SUM('Table'[cost])),,ASC,Dense))

 

 

 

205.png

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

  • If expression or value evaluates to BLANK it is treated as a 0 (zero) for all expressions that result in a number, or as an empty text for all text expressions.

  • If value is not among all possible values of expression then RANKX temporarily adds value to the values from expression and re-evaluates RANKX to determine the proper rank of value.

  • Optional arguments might be skipped by placing an empty comma (,) in the argument list, i.e. RANKX(Inventory, [InventoryCost],,,"Dense")

  • This function is not supported for use in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.

amitchandak
Super User
Super User

@ngct1112 , Try like

 

new Rank = RANKX( filter(ALLSELECTED(Table[Items],Table[Products]), Table[Products] =max(Table[Products])), CALCULATE(SUM('Table'[cost])),,ASC)

 

Ranking of cost(DESC) = IF([Ranking of Products(ASC)]=1,[new Rank ], blank())

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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