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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
xuantalks
Frequent Visitor

RANKX DAX function doesn't work as I expect

 

Hi guys, 
I'm new in Power BI and DAX. I face any issue using RANKX DAX function. Could you please have a look and give me advice?

There 2 tables as below

data.PNG

 

What I'm trying to do is add 2 columns InsurerRank and InsurerGroupRank based on Total Net Earnings

 

Result.PNG

I created a measure:

Total Net Earnings = SUM(Net Earnings)


I also added 2 columns into Insurers table:
InsurerRank = RANKX(ALL(Insurers), [Total Net Earnings])
InsurerGroupRank = RANKX(ALL(Insurers[Insurer Group]),[Total Net Earnings],, DESC)

 

But the result was not correct

 

 1.png

2.png

1 ACCEPTED SOLUTION

HI @xuantalks,

 

You can try to use following calculate column to replace group with other based on their ranking.

Top 5 Group =
VAR summary =
    SUMMARIZE (
        ADDCOLUMNS ( Policy_Transactions, "Group", RELATED ( Insurers[Insurer_Group] ) ),
        [Group],
        "Total", SUM ( Policy_Transactions[Net_Earnings] )
    )
VAR _rank =
    COUNTROWS (
        FILTER (
            summary,
            [Total]
                > MAXX (
                    FILTER ( summary, [Group] = EARLIER ( Insurers[Insurer_Group] ) ),
                    [Total]
                )
        )
    )
        + 1
RETURN
    IF ( _rank > 5, "Other", [Insurer_Group] )

12.png

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

7 REPLIES 7
v-shex-msft
Community Support
Community Support

Hi @xuantalks,

 

If you mean you want to show dynamic rank based on current filter, I'd like to suggest you use allselected to replace all function and add additional parameter 'dense' to your formula.

InsurerRank =
RANKX ( ALLSELECTED ( Insurers ), [Total Net Earnings],, DESC, DENSE )

InsurerGroupRank =
RANKX (
    ALLSELECTED ( Insurers[Insurer Group] ),
    [Total Net Earnings],
    ,
    DESC,
    DENSE
)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft InsuerGroupRank formula that you suggested returns 1 for every single Insurer Group

 

4.PNG

Hi @xuantalks,

 

Can you please share a pbix file with some sample data for test?

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

hi @v-shex-msft 

 

Here it is data sample. Could you have a look?

 

Thanks a lot,

Xuan

HI @xuantalks,

 

You can try to use following calculate column to replace group with other based on their ranking.

Top 5 Group =
VAR summary =
    SUMMARIZE (
        ADDCOLUMNS ( Policy_Transactions, "Group", RELATED ( Insurers[Insurer_Group] ) ),
        [Group],
        "Total", SUM ( Policy_Transactions[Net_Earnings] )
    )
VAR _rank =
    COUNTROWS (
        FILTER (
            summary,
            [Total]
                > MAXX (
                    FILTER ( summary, [Group] = EARLIER ( Insurers[Insurer_Group] ) ),
                    [Total]
                )
        )
    )
        + 1
RETURN
    IF ( _rank > 5, "Other", [Insurer_Group] )

12.png

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks alot @v-shex-msft. It works

rajulshah
Super User
Super User

Hello @xuantalks,

 

Did you try using "Dense" or "Skip" property in RANKX function?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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