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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Rankx Multiple levels to Hierarchy

I am trying to rank different stores based on Sales.  These stores are also broken out by Country, Region, District.

 

I would like to be able to rank the countries against each other, the Regions, and the districts.

 

Something like this all in one matrix.  What would be the correct Formula for this?

 

USA 1                                                  RANK 1  

                 US Central                          RANK 2

                                    STORE 1           RANK2

                                    STORE 3           RANK 3

                                    STORE 4            RANK 1  

                 US EAST                              RANK 1

                 US South                            RANK 3

 

China                                                   RANK 3

Canada                                                RANK 2

 

 rankx.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous,

 

Nope, you can't direct write a simple formula to achieve multiple level ranking.

 

In my opinion, your formula should nested with multiple ranking formulas based on each level and concatenate by if statement. After these, you can use if statement to check current level and use correspond ranking formula.

 

You can take a look at below is a blog, it told about how to use if statement to check current hierarchy level.

Clever Hierarchy Handling in DAX

 

Regards,

Xiaoxin Sheng

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous,

 

Nope, you can't direct write a simple formula to achieve multiple level ranking.

 

In my opinion, your formula should nested with multiple ranking formulas based on each level and concatenate by if statement. After these, you can use if statement to check current level and use correspond ranking formula.

 

You can take a look at below is a blog, it told about how to use if statement to check current hierarchy level.

Clever Hierarchy Handling in DAX

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Thanks @Anonymous  Xiaoxin.... That did the trick...

 

Here was my final dax formula.

 

Rank = IF (
ISFILTERED (dim_location_view[StoreDescription]),
rankx(all(dim_location_view[StoreDescription]),[Total Plan])
, IF(
ISFILTERED (dim_location_view[DistrictNumAndDesc]),
rankx(all(dim_location_view[DistrictNumAndDesc]),[Total Plan])
, IF(
ISFILTERED (dim_location_view[RegionNumAndDesc]),
rankx(all(dim_location_view[RegionNumAndDesc]),[Total Plan])
,
IF(
ISFILTERED (dim_location_view[ZoneName]),
rankx(all(dim_location_view[ZoneName]),[Total Plan])))))
 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.