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

RankX at Category level for Category/SubCategory context

Hi - looking for some help with a RankX DAX calculation.  For illustrative purposes, I'm using a simple table with Category, SubCategory, and Value.  I'd like to create a measure that ranks by Category for total value across all SubCategory.  

 

Currently, the measure is:

CategoryRank = RANKX(ALL('Table'[Category]), CALCULATE(SUM('Table'[Value])))
 
This works when SubCategory is excluded. However, when I include SubCategory, it evaluates across the unique combinations.
 
What I'd like to return is a table like:

 

CategoryRank Category SubCategory Value
4 D D1 9,936

1 A A4 9,507

2 B B1 9,446

etc

 

Capture.PNG

 

pbix drobbox link

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

A measure like this should work

CategoryRank = RANKX(ALL('Table'[Category]), CALCULATE(SUM('Table'[Value]), ALLEXCEPT('Table','Table'[Category])))

View solution in original post

9 REPLIES 9
v-deddai1-msft
Community Support
Community Support

Hi @brentmav ,

 

According to your description, my understanding is that you want to rank your data by category and subcategory in a measure. If anything is misunderstood, please tell me.

 

Would you please create a measure to determine whether it is a Category or SubCategory?

 

 

ISCategory = COUNTROWS('Table') = CALCULATE(COUNTROWS('Table'),ALL('Table'), VALUES('Table'[Category]))

 

 

Then create a measure for ranking:

 

 

CategoryRank = IF( [ISCategory], RANKX( ALLSELECTED('Table'[Category]),CALCULATE(SUM('Table'[Value]))), RANKX(ALLSELECTED('Table'[SubCategory]),CALCULATE(SUM('Table'[Value]))))

 

 

Untitled picture.png

 

 

For more details, please refer to https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/Ee2raMYlhUJEk0MhAd...

 

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

 

Best Regards,

Dedmon Dai

Ashish_Mathur
Super User
Super User

Hi,

I am not sure of what you want but see if my solution in this file helps.

Untitled.png


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

Ashish Sir,

 

I also need this solution for my office assigment please share the DAX formula. In my assinnments there area 5 categoriues like 2 Regions, 7 Zones, 24 Branches and 45 Area Sales Officers, i want to making ranking from between Retions, then Zones, then brnahes then area sales officers... please guide. 

Hi,

I do not have that file now.  Share some data and show the expected result.


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

Dear Sir,

Reference data is attached.

Thank You so much for support.

https://drive.google.com/file/d/18ULxB7JdQXjqQszXQHw9BQ28lazJsD5X/view?usp=sharing

 

Share the download link of Excel and/or PBI file and show the expected result clearly.


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

Dear Sir,

Reference data is attached.

Thank You so much for support.

https://drive.google.com/file/d/18ULxB7JdQXjqQszXQHw9BQ28lazJsD5X/view?usp=sharing

HotChilli
Super User
Super User

A measure like this should work

CategoryRank = RANKX(ALL('Table'[Category]), CALCULATE(SUM('Table'[Value]), ALLEXCEPT('Table','Table'[Category])))

Thank you very much! Definitely wasted too much time trying to figure this one out!

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.