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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
JayJay11
Resolver II
Resolver II

Dynamic Ranking of Product in Hierarchy

Hello all,

 

this is the first I am completely stuck with a problem in DAX. My problem is supposedly simple, but I believe the RANKX function is very hard to apply in real-world problems.

 

Desired end-result

I simply want to rank 3 products in a geographical hierarchy, considering also the slicer context of the report page (geography and a date range).

 

Both rows and columns are based on fields. Ideally, the table has just one measure.

 

The ranking shall be based on the latest date selected on the sheet.

 

DAX Problem 1.PNG

This is the fact table

DAX Problem 2.PNG

This is the geography table

DAX Problem 3.PNG

 

The date table is just a standard calender connected via the date field.

 

I understand from reading countless other posts on RANKX issues, that in the end I could generate mutiple variables in a measure and then check with ISFILTERED() the current hierarchy level. I guess the issue that I have, is how to calculate the ranking on an aggregated level, like here Subregion?

 

Can someone provide a solution pattern for this?

 

Many thanks in advance!

1 ACCEPTED SOLUTION

Hi, @JayJay11 

 

Measure:

Rank Measure =
RANKX (
    FILTER (
        ALL ( 'Fact' ),
        [Country_ISO] = MAX ( 'Fact'[Country_ISO] )
            && [Date] = MAX ( 'Fact'[Date] )
    ),
    CALCULATE ( SUM ( 'Fact'[Value] ) ),
    ,
)

vzhangti_0-1641953659445.png

 

Best Regards,

Community Support Team _Charlotte

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

6 REPLIES 6
v-zhangti
Community Support
Community Support

Hi, @JayJay11 

 

You can try the following methods.

New column:

Rank =
RANKX (
    FILTER (
        'Fact',
        [Country_ISO] = EARLIER ( 'Fact'[Country_ISO] )
            && [Date] = EARLIER ( 'Fact'[Date] )
    ),
    [Value],
    ,
    DESC
)

vzhangti_0-1641891010716.png vzhangti_1-1641891026364.png

Is this the output you expect?

 

Best Regards,

Charlotte Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Dear Charlotte,

 

many thanks for this suggestion. I understand, this solution uses a calculated column. We however need the ranking to be dynamic and change with the filter context. As such, a measure would be needed.

 

Do you have a solution for a measure?

 

Thank you!

Hi, @JayJay11 

 

Measure:

Rank Measure =
RANKX (
    FILTER (
        ALL ( 'Fact' ),
        [Country_ISO] = MAX ( 'Fact'[Country_ISO] )
            && [Date] = MAX ( 'Fact'[Date] )
    ),
    CALCULATE ( SUM ( 'Fact'[Value] ) ),
    ,
)

vzhangti_0-1641953659445.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

JayJay11
Resolver II
Resolver II

No one? Is this actually unsolvable with DAX?

smpa01
Super User
Super User

@JayJay11  provide sample data first

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

@smpa01 here is some sample data, does that suffice?

 

ProductISO_CountryDateValue
Product 1CH01.12.20217.153871417
Product 2CH01.12.20214.791841636
Product 3CH01.12.20218.671030065
Product 1DE01.12.20210.252021849
Product 2DE01.12.20217.39999411
Product 3DE01.12.20218.051734496
Product 1NO01.12.20217.503697651
Product 2NO01.12.20217.239210549
Product 3NO01.12.20211.123777987
Product 1SW01.12.20217.806173907
Product 2SW01.12.20213.857131311
Product 3SW01.12.20211.251952541
Product 1CH01.09.20214.609087907
Product 2CH01.09.20212.179643813
Product 3CH01.09.20219.386766622
Product 1DE01.09.20212.530506259
Product 2DE01.09.20218.964522569
Product 3DE01.09.20214.387980849
Product 1NO01.09.20210.810266905
Product 2NO01.09.20217.841674418
Product 3NO01.09.20211.120149594
Product 1SW01.09.20211.099291771
Product 2SW01.09.20214.258235797
Product 3SW01.09.20214.891234175

 

Country_ISOCountrySubregionRegion
CHSwitzerlandWestern EuropeEurope
DEGermanyWestern EuropeEurope
NONorwayNorthern EuropeEurope
SWSwedenNorthern EuropeEurope

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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