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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
goatmonslc
Frequent Visitor

RANK by category?

Hello all!

 

Looking for some guidance on how to resolve the following scenario.

 

I have two tables:

 

FACTS

RecordID (number)

BusinessUnit (text)

ReportNum (text)

 

CODES TABLE

Code (text)

CodeType (text)

ReportNum (text)

 

I have a relationship between these two tables using ReportNum (one->many). I'm trying to create a matrix table that will show the top 5 codes for each BusinessUnit using the count of the ReportNum. I've read lots of posts, etc. about RANKX but a lot of the examples use calculation of "total sales" or other numerical values. I've tried replacing some of the code with COUNT instead, but I am still not getting the results I'm looking for. It seems to be calculating the same total count for each business unit and code. Either that, or it's calculating the ranking based on just the code, and not the BU+Code. Here is what I am looking for, as far as output in a visualization (matrix table form):

 

Business Unit/Code

BU1

Insufficient Information, 120

Foreign Matter, 99

Swelling, 15

Seroma, 6

Pain, 2

BU2

Discomfort, 344

Blister, 42

Headache, 41

Fatigue, 12

Pain, 9

 

Any help would be sooo appreciated!

Dee

1 ACCEPTED SOLUTION
goatmonslc
Frequent Visitor

Sorry for so many replies! I figured out that this is working as long as I have all of the data in one table. I wasn't sure how to rank the count of codes, where the codes were in the "many" table of the one-many relationship between my facts table and my code table. What I ended up doing was adding a new calculated column into my CODES table to pull the name of the BusinessUnit in using the RELATED calculation. Now if I perform my ranking all in one table (the CODES table) it's working fine. I'm still curious how this would be able to work, however, using both tables!

View solution in original post

5 REPLIES 5
goatmonslc
Frequent Visitor

Sorry for so many replies! I figured out that this is working as long as I have all of the data in one table. I wasn't sure how to rank the count of codes, where the codes were in the "many" table of the one-many relationship between my facts table and my code table. What I ended up doing was adding a new calculated column into my CODES table to pull the name of the BusinessUnit in using the RELATED calculation. Now if I perform my ranking all in one table (the CODES table) it's working fine. I'm still curious how this would be able to work, however, using both tables!

Anonymous
Not applicable

Hi, @goatmonslc 

It looks like you have found a solution. Could you please mark this helpful post as “Answered”?

This will help others in the community to easily find a solution if they are experiencing the same problem as you.

Thank you for your cooperation!

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Did you try to create a simple measure with the count, and then use it to filter the visualize with a rank?

Yes, I have a measure called "CodeCount":

CodeCount = COUNT('Codes'[ReportNum])
 
My rank:
CodeRank = RANKX(ALL('Codes'[Code]),Measures_Table[CodeCount])
 
When I use the CodeRank to filter the visual (CodeRank<6) it doesn't actually filter anything under the BusinessUnit. I get all of the counts for all of the codes under each BusinessUnit. I have tried different rank measures, but can't seem to get it right.

OK the count is working, my Rank shows up with ranking 1 for each BusinessUnit 'Code'.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.