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
shep123
Helper I
Helper I

Rank within Category but ignore subcategory

I am trying to create a rank measure within an specific categories but ignore others. I have seen a lot of similar questions asked but couldn't find one that did exactly what I needed.

 

Sample Data

Order StatusOrder IDAccount IDOrder $Rank (Desired)
DeliveredaaaCust A1001
DeliveredbbbCust B502
DeliveredcccCust A303
ShippeddddCust C751
ShippedeeeCust D402
ReceivedfffCust B2001
ReceivedgggCust E152
ReceivedhhhCust A103

 

My current formula is:

Rank = IF(HASONEVALUE('Table'[Order ID]), RANKX(ALL('Table'[Order ID]), CALCULATE(SUM('Table'[Order $]))), BLANK())
This works for all scenarios where I don't include the Account ID in the matrix but breaks once I added that attribute in. That is a necessary attribute as I want to rank by Orders within the Order Status category but allow the user to easy see the customer name as well.
 
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@shep123 

Use the following measure to calculate the rank as desired:

Rank = 

RANKX(
    ALLEXCEPT(Table,Table[Order Status]),
    CALCULATE(SUM(Table[Order $]))
)

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
hrishi
Helper I
Helper I

Hello, 

Could you please guide me on this issue.
I tried the same way of creating the measure and the measure will work when you have one category however as soon as you add another category (sub category) the ranking changes. 

Is there any way to define global ranking on a category?

 

Looking forward to your response 🙂 

Thank you!

Jolanda18
New Member

Hi all, I have a similar issue only the formula presented does not solve it. Let me explain my situation, hopefully you are able to help me out.

 I have a table like this (much bigger table actually but as an example)

 Table 1                                                              

Customer  Country              Country Group     Sales

ABC         Netherlands        Benelux                100

ABC         Belgium              Benelux                50

DEF          Netherlands        Benelux                200

GHI          Netherlands        Benelux                75

JKL           Belgium              Benelux                20

 and I was using the formula to rank them:Customer Rank TO = RANKX(ALL('table1'[Customer]), CALCULATE(SUM('table1'[Sales]),allexcept('table1','table1'[Customer]),,DESC,Dense)

 when plotting this in a matrix, it works fine:

Customer  Sales                  Customer Rank TO

DEF          200                    1

ABC         150                    2

GHI          75                      3

JKL           20                      4

 And I can show the top 2 by setting a threshold of 2

[Customer Rank TO]<=2

Customer  Sales                  Customer Rank TO

DEF          200                    1

ABC         150                    2

 However, when I bring in country into the matrix, it does not keep the ranking on total sales by customer anymore but takes a customer-country perspective and I get more results than 2. This happens because the logic looks at the top 2 of the individual countries. JKL is in the top 2 of Belgium (but not a top 2 of Benelux). I want it to keep looking to the overall ranking and not by country. How to solve this? 

I tried the formula: Customer Rank TO = RANKX(ALLexcept('table1','table1'[Customer]), CALCULATE(SUM('table1'[Sales])),,DESC,Dense) but I then don't get results (not enough memory). Any suggestion on how I can solve? 

Thanks for your kind help!

shep123
Helper I
Helper I

Thank you in everything I tried I somehow didn't that solution

How would I adjust this formula if I wanted to be dynamic from another filter like order month for example? Based on my testing the ranks stay the same even if I filter out certain orders based on what was ordered that month.

Fowmy
Super User
Super User

@shep123 

Use the following measure to calculate the rank as desired:

Rank = 

RANKX(
    ALLEXCEPT(Table,Table[Order Status]),
    CALCULATE(SUM(Table[Order $]))
)

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.

Top Solution Authors