cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
S_GI
Frequent Visitor

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
yingyinr
Community Support
Community Support

Hi @S_GI ,

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

@S_GI 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.





S_GI
Frequent Visitor

@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 

yingyinr
Community Support
Community Support

Hi @S_GI ,

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

S_GI
Frequent Visitor

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

Helpful resources

Announcements
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors