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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

RANKX returns unexpected results

Hi,

I'm trying to create a measure that ranks a table based on a score, but I can't seem to get the rank to work as expected. I've looked through threads that have reported similar issues that I have, but the solutions to those threads don't seem to work when applied to my instance. 

 

My table looks like the following:

data.png

 

The report itself consists of a slicer, where you can select between the different KPIs, and a matrix diagram that looks like the following:

matrix.png

 

What I would like to do is to create a measure that ranks the different stores by doing a sum() of all the ranks (that are in the dataset) that are included in the selected values in the slicer. The Store with the lowest rank should be rated as 1. The ranking should be updated based on the KPIs that are selected in the slicer.

I've created a measure with the following script that seems to work when I've only selected 1 option in the slicer:

Overall Ranking = 
RANKX(
    ALLSELECTED(Sheet1),
    CALCULATE(SUM(Sheet1[Rank])),
    ,
    ASC,
    Dense
)

 

But as soon as I select more options then the ranking seems to return something else. For example in the below screenshot, I've selected 2 options in the slicer. The Score (which is a different measure that I've created and is just a sum() of the ranks of the selected values) indicates that the ranking should be 2, 1, 2, 3, but instead the ranking is 5, 4, 5, 5
issue.png

When there is only 1 value selected in the slicer, then the ranking looks like the following (which is correct):

single.png

 

Could you help me find out what I'm doing wrong?

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Please create new measure to get the sum of Rank, then update the formula of measure [Overall Ranking] as below. Please find the attachment for the details.

Sum of Rank = SUM('Sheet1'[Rank])
Overall Ranking = 
VAR tab1 =
    SUMMARIZE ( ALLSELECTED ( Sheet1 ), Sheet1[Store], "sumofRank", [Sum of Rank] )
RETURN
    RANKX ( tab1, [Sum of Rank],, ASC, DENSE )

yingyinr_0-1630400409934.png

Best Regards

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

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@Anonymous not sure why, can you share pbix file, remove sensitive information before sharing.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k I can't upload the file directly to this forum so I hope that a drive link works for you. Thanks for helping me look into this! 
https://drive.google.com/file/d/1-tJ_Lf7wvml1FvGR1xdeXAg96c4hdxHD/view?usp=sharing 

Hi @Anonymous ,

Please create new measure to get the sum of Rank, then update the formula of measure [Overall Ranking] as below. Please find the attachment for the details.

Sum of Rank = SUM('Sheet1'[Rank])
Overall Ranking = 
VAR tab1 =
    SUMMARIZE ( ALLSELECTED ( Sheet1 ), Sheet1[Store], "sumofRank", [Sum of Rank] )
RETURN
    RANKX ( tab1, [Sum of Rank],, ASC, DENSE )

yingyinr_0-1630400409934.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-yiruan-msft It works perfectly! Thank you so much for the help!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.