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
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())

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())

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.