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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Ani26
Helper III
Helper III

RANKX function not giving correct results

Hi Team,
Wish you all a very happy new year !!
Need your help today with one of the requirement.

We have a data model in Power BI with one fact and few dimensions. The requirement is we are pulling fields from different dimensions and the measures from the fact table. Now what we need is to create a measure to show the ranking based on the Sales% value and to show only the top 10.

To quickly summarize, the table looks something like this

FNameProviderRegionSalesSales%
AngelaNYKEMEA110.22.5

 

Since this is a kind of a dimensional modelling, I used the crossjoin function and created the DAX measure like below.

 

TF_Rank_QTD_Region = 
var top10 = IF( 
                NOT ISBLANK([Sales%]),
                    rankx(CROSSJOIN(ALLSELECTED('FProvider'[FName]),ALLSELECTED('Provider'[Provider]),ALLSELECTED('Region'[ Region])),[Sales%],,DESC,Dense)
            )
RETURN
IF(top10 <= 10 , top10 , BLANK())

 

 But when I pull this measure in the above table I get repeated ranks based on each region like below.

TF_Rank_QTD_RegionFNameProviderRegionSalesSales%
1AngelaNYKEMEA110.22.5
1JemeNYKASIA78.31
1ChilNYKAMERICAS31.51.5
2WerenNYKEMEA23.62.1
2BradNYKASIA1.60.8
2SachNYKAMERICAS1.51.5
3SewrNYKEMEA2.71.4
3VenuaNYKASIA4.60.4
3GeorgNYKAMERICAS2.50.3
4AssenNYKEMEA12.21.1
4AmwyNYKASIA6.40.3
4DeniaNYKAMERICAS1.20.3
5FilloNYKEMEA53.41.1
5RichiNYKASIA0.30.3
5CinthisaNYKAMERICAS3.70.3

 

I tried many different combinations but still the rank repeats. The relationship from the dimensions to the fact table is one to many. 
The required output is unique ranks based on Sales% in desc order.

TF_Rank_QTD_RegionFNameProviderRegionSalesSales%
1AngelaNYKEMEA110.22.5
2WerenNYKEMEA23.62.1
3SewrNYKEMEA2.71.4
4AssenNYKEMEA12.21.1
5FilloNYKEMEA53.40.9


May I understand if I am doing something wrong?  Any help will be highy appreciated.
Also kindly let me know if any additional information required.

 

Regards,

Ani

1 ACCEPTED SOLUTION
Ani26
Helper III
Helper III

Hi All,

Sorry for a delayed reply. 
I got this resolved. Actually the issue was Column Region had a sort by on it by another column which was actually causing the ranking to give incorrect results. As soon as I removed the sorting by another column, the DAX formula (in the description) gave me the correct results.

@parry2k  and @smpa01 thank you so much for help and assistance.

 

Thanks.
Ani

View solution in original post

13 REPLIES 13
Ani26
Helper III
Helper III

Hi All,

Sorry for a delayed reply. 
I got this resolved. Actually the issue was Column Region had a sort by on it by another column which was actually causing the ranking to give incorrect results. As soon as I removed the sorting by another column, the DAX formula (in the description) gave me the correct results.

@parry2k  and @smpa01 thank you so much for help and assistance.

 

Thanks.
Ani

parry2k
Super User
Super User

@Ani26 you keep on referring me @smpa01  which is cool. Hmm, very hard to tell what is going on. Can you create dummy pbix file and send me via email, my email is in my signature.

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!



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.

Ohh God.
My sincere apologies @parry2k. Extremely sorry for that.
I will try to replicate the issue in a sample pbix and will send it to you over email.

parry2k
Super User
Super User

@Ani26 can you make sure in the visual you are using Region from the region dimension not from the fact table, just making sure.

 

 



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.

Yes @parry2k , that is handled correctly.

parry2k
Super User
Super User

@Ani26 to clarify, you are saying if you keep the Region in the visual, it works, and if you remove the region it doesn't work. correct?



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.

Hi @parry2k 
Rather the opposite.
If I remove the Region field from the visual it works but if I pull the region field it gives incorrect ranking.

parry2k
Super User
Super User

@Ani26 ok try this measure:

 

TF_Rank_QTD_Region = 
 RANKX ( SUMMARIZE ( ALLSELECTED ( YourFactTable ), 'FProvider'[FName], 'Provider'[Provider], 'Region'[ Region] ), [Sales%], , DESC ) 

 

Tweak it as you see fit, but first, check if you get the correct rank.

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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.

I tried the DAX measure but still no change. The thing I noticed is , till the time I don't pull in the Region field the rank shows up correctly. As soon as I pull the Region field, the ranks duplicates itself as per the unique values in the region table (that is 3 times.)

smpa01
Super User
Super User

@Ani26  can you please create  a sample pbix and provide here?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01 
My sincere apologies but I am not getting the option to attach a pbix here. Since this been an organization system I don't have access to save it on a drive and provide the link.

parry2k
Super User
Super User

@Ani26 read this post to get ranked by category and subcategory and the same applies in your situation. How to use RANKX in DAX (Part 2 of 3 – Calculated Measures) - RADACAD

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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.

Hi @parry2k 
Thank you for providing the link. I went through the link provided by you but in that the DAX measures are created for fields coming from the same table whereas in my case  I am pulling fields from different dimension tables and measure values from Fact table.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors