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
twintrbl
Advocate I
Advocate I

Rank with two categories

I'm trying to rank our Vendors by their average survey scores, but I need it ranked not just by the Vendor, but by the Vendor and the State.  Over-simplified example:

 

samplerank1.png

 

I have tried all kinds of ways to make this work, but I'm ending up with results that make no sense. If I use:

 

RANKX(
ALL('Dispatch'[Vendor]),
CALCULATE ( AVERAGE ( Survey[Rating]))
)

Even though I have the State in the Table, I can't begin to decipher what it's doing. I have it sorted descending on the Average Rating, but the rankings make no sense.

 

samplerank2.png

 

I'm guessing it's related to not having State reflected in the Rank formula. So I tried creating a new column that combined both Vendor and State into a single column ([Vendor&State]), so I can then refer to it in the formula. 

 

RANKX(
ALL('Dispatch'[Vendor&State]),
CALCULATE ( AVERAGE ( Survey[Rating]))
)

And it seemed to work.

 

samplerank3.png

 

(Yes, there are 692 that have 5.000 and therefore rank 1, so the next highest is correctly showing as 693.) But I don't want a single ugly column showing the Vendor and State mashed together, and someone might want to sort or filter it by state OR Vendor, so I was trying to add the Vendor and State columns back into the table. I added State and it went back to the crazy rankings in the first screenshot - 1, 65, 72, ....

So now I'm lost and thinking I need to approach this in a totally different way, but I don't know how to use two columns as the ranking category, with one measure (actually the Average of a column value) as the value. Where do I even start?

And this is just the beginning, since I need to add two other measures to the table once I get rank corrected (the # of surveys returned and the response rate), and I'm afraid those will make the rank measure go psychotic again.

Ideas? I'm feeling really stupid because this seems such a basic application of a ranking measure, but nothing is working.

FWIW, I've tried adding an 
IF ( HASONEVALUE ( 'Dispatch'[Vendor&State]),

to the formula, or changing the

ALL() to ALLSELECTED() 

But neither one makes any difference.

 

Thanks in advance for any suggestions!

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @twintrbl 

You can feed more than one column into your ALL statement which will give you the combined list to rank over.  Give this a try.

Ranking =
RANKX (
    ALL ( 'Dispatch'[Vendor], 'Dispatch'[State] ),
    CALCULATE ( AVERAGE ( Survey[Rating] ) )
)

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

Hello @twintrbl 

You can feed more than one column into your ALL statement which will give you the combined list to rank over.  Give this a try.

Ranking =
RANKX (
    ALL ( 'Dispatch'[Vendor], 'Dispatch'[State] ),
    CALCULATE ( AVERAGE ( Survey[Rating] ) )
)

@jdbuchanan71  Thank you! That worked! I knew it had to be something simple. I just never saw any examples with two columns in the ALL statement. Thank you for taking the time to reply!

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.