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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
aleivar
Frequent Visitor

RANKX in matrix table

Hi All,

I am trying to use single RANKX formula in a matrix table so that the rank is calculated correctly when I drill down.

The image below shows the correct rank for LP

aleivar_0-1680801159476.png

 

But when I drill down, the rank is not calculated correctly. The Rank Total Sales (Brand) shows the correct rank

aleivar_1-1680801249901.png


I tried the following RANK formula but it's not calculating correctly

 

 

 

Rank Total Sales = 
VAR LPGROUPRANK =
RANKX(
    ALL(
        'OCS-daily-2018-2023'[lp_group]
    ),
    [Total Sales],
    ,
    DESC,
    Dense
)
VAR BRANDRANK =
RANKX(
    ALLSELECTED(
        'OCS-daily-2018-2023'[brand]
    ),
    [Total Sales],
    ,
    DESC,
    Dense
)
RETURN
SWITCH(
    TRUE(),
    ISINSCOPE('OCS-daily-2018-2023'[lp_group]
    ),
    LPGROUPRANK,
    ISINSCOPE(
        'OCS-daily-2018-2023'[brand]
    ),
    BRANDRANK
)

 

 


My model looks like this:

aleivar_2-1680801355896.png

 

Any help is greatly appreciated

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @aleivar 

You can try the following measure

Rank Total Sales =
VAR LPGROUPRANK =
    RANKX (
        ALLSELECTED ( 'OCS-daily-2018-2023'[lp_group] ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
VAR BRANDRANK =
    RANKX (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'OCS-daily-2018-2023' ),
                [lp_group] = SELECTEDVALUE ( 'OCS-daily-2018-2023'[lp_group] )
            ),
            [brand]
        ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( ISINSCOPE ( 'OCS-daily-2018-2023'[brand] ), BRANDRANK, LPGROUPRANK )

 

Best Regards!

Yolo Zhu

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

1 REPLY 1
v-xinruzhu-msft
Community Support
Community Support

Hi @aleivar 

You can try the following measure

Rank Total Sales =
VAR LPGROUPRANK =
    RANKX (
        ALLSELECTED ( 'OCS-daily-2018-2023'[lp_group] ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
VAR BRANDRANK =
    RANKX (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'OCS-daily-2018-2023' ),
                [lp_group] = SELECTEDVALUE ( 'OCS-daily-2018-2023'[lp_group] )
            ),
            [brand]
        ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( ISINSCOPE ( 'OCS-daily-2018-2023'[brand] ), BRANDRANK, LPGROUPRANK )

 

Best Regards!

Yolo Zhu

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

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.