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
Young_G_Han
Helper III
Helper III

Rankx with the column that is sorted by other column in the data table

Hello.

 

I have a problem with the rankx formula.

 

Code     Name

1           Bread

2           Onion

3           Cake

4           Pizza

 

I have a list of products and the related code. I want to sort the name of the product by the code, not by alphabetic order.

So I arrange the column with the code.

 

When I make a ranking column with the rankx, it shows only 1 for the ranking as below.

 

Ranking   Name    Value

1              Pizza      10,000

1              Onion     8,000

1              Bread      5,000

1              Cake       3,000

 

 

What I want is.... when I sort the table by Value.

 

Ranking   Name    Value

1              Pizza      10,000

2              Onion     8,000

3              Bread      5,000

4              Cake       3,000

 

 

When I sort the table by Name.

 

Ranking   Name    Value

3              Bread      5,000

2              Onion     8,000

4              Cake       3,000

1              Pizza      10,000

 

 

I used the following formula. If I am wrong, please let me have the correct formula.

 

Calculate(rankx(product[Name], [Value], ,Desc), allselected(product[Code])

1 ACCEPTED SOLUTION
dhruvinushah
Responsive Resident
Responsive Resident

Hi, @Young_G_Han  Try this: 

FoodRank = 
RANKX (
    ALLSELECTED ( 'TableTest'[Name], 'TableTest'[Order] ),
    CALCULATE ( SUM ( 'TableTest'[Value] ) ),
    ,
    DESC
)

 

Hope this helps. 









View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Try this measure

Amount = sum(Data[Value])

Rank = rankx(all(Data[Name]),[Amount])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
dhruvinushah
Responsive Resident
Responsive Resident

Hi, @Young_G_Han  Try this: 

FoodRank = 
RANKX (
    ALLSELECTED ( 'TableTest'[Name], 'TableTest'[Order] ),
    CALCULATE ( SUM ( 'TableTest'[Value] ) ),
    ,
    DESC
)

 

Hope this helps. 









Great Thanks it is working!!

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.