cancel
Showing results for 
Search instead for 
Did you mean: 
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.






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

@yingyinr It works perfectly! Thank you so much for the help!

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.