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
TexasBI
Helper II
Helper II

Ranking with row counts

Hello,

 

I have tried everywhere and everywhich way but I can not get ranking to work when using COUNT. Maybe data looks something like this:

Item

A

B
C
A
C
A
C

 

Then when you put it into a table in Power BI with one column being the [Item] and the other as Count of [Item] you would get something like this..

 

ItemItem Count
A3
B1
C3

 

Then once I add this RANKX measure I get nothing but 1s:

RANKX (
       ALLSELECTED(exampleTable)

       CALCULATE(COUNT( [Item] )

       , , DESC , DENSE
)

What is going on and what am I doing wrong?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@TexasBI - Yep, replacing ALLSELECTED with ALL works.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@TexasBI - Yep, replacing ALLSELECTED with ALL works.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hey @Greg_Deckler ,

 

That did not work. Here is my code and here is my result.

_testRank =

RANKX(
ALLSELECTED(CUSTOMER_FEEDBACK),
CALCULATE(COUNTROWS(CUSTOMER_FEEDBACK)),,DESC,Dense
)
 
Capture4.PNG
 
The source table has +1K rows. Each row is a single customer feedback. Each row has an assigned feedback category. I am trying to do a running total on the aggregated count for each category so i can build a pareto chart. Since some categories have the exact same count i can not use RANKX.

@TexasBI - It is hard to say. Take a look at Table (3) and the associated visual of the attached PBIX file.  I took your sample data and just created this measure:

 

Rank = RANKX(ALL('Table (3)'),CALCULATE(COUNT([Item])),,DESC,Dense)
 
 

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hey @Greg_Deckler  thank you for putting that together. I think I may have confused everyone when needing a rank. I was hoping to use RANKX but once you have duplicate values, then you get duplicate ranks which throws your ability to calculate a running total off for a Pareto chart. 

 

What I need is to be able to do a running total on that count measure column and also be dynamic so when I filter the source table by different variables, the running total maeasure runs based off that count measure. I hope that makes sense?

Greg_Deckler
Super User
Super User

@TexasBI - Replace ALLSELECTED with ALL I would think. Try that while I test it out. Also, see To *Bleep* with RANKX, you may not have to use it but now you understand how that quick measure was named!!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.