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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
maurcoll
Helper II
Helper II

Rankx and sort

Good Afternoon

 

I am using the following formula to rank store sales, by store and region.

Store Ranking % sales =
RANKX ( ALL(Region[Store]),
[% Sales], , ASCDense)

Store Ranking % sales =
RANKX ( ALL(Region[Store]),
[% Sales], , Desc Dense)

I have a table of results for regions which i then filter down to stores within the region.
The issue i have is that when i use asc, the ranking starts from 2, when i use desc the ranking starts from 1.
The reason i have both calculations is that for some types of sales i want to use ascending instead of descending
 
Any ideas in how to deal with this?
 
RegionStoreSalesRank
NorthA10%1
NorthB20%2
SouthA30%3
1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @maurcoll,

 

Can you please try this DAX:

Store Ranking % sales (ASC) =
RANKX(
    FILTER(ALL(Region[Store]), [Measure for % Sales] > 0),
    [% Sales], , ASC, Dense
)

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
Sahir_Maharaj
Super User
Super User

Hello @maurcoll,

 

Can you please try this DAX:

Store Ranking % sales (ASC) =
RANKX(
    FILTER(ALL(Region[Store]), [Measure for % Sales] > 0),
    [% Sales], , ASC, Dense
)

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Good morning, 

That is working for the majoirty it is only when i have a store with 0 sales that it is giving this store and the next store a ranking of 1, when all stores have sales it is working perfectly. Ideally i would like the 0% to be 1 and then the next store to show as 2. I have tried changing from skip to dense but this does not seem to make any difference. Thank you for your help

 

Store% SalesRanking
A1%1
B0%1
C1.5%2

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.