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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
AC23VM
Helper II
Helper II

Breaking RANKX ties - calendar issue?

Hi there.  I've been having trouble for a few days trying to break RANKX ties.  I've tried adding in unique identifiers and random numbers, but it's not breaking the ties.  I've had no luck with Copilot, and suggestions here don't seem to be working.  Very likely, it's my issue in not having the DAX right, but I wonder if anyone could please suggest a fix?  In trying to determine a top 5 count, I've got this far:

LowerLevelRootCauseCount =
CALCULATE(
    COUNTROWS('Outcomes Testing Data'),
    ALLEXCEPT('Outcomes Testing Data', 'Outcomes Testing Data'[Lower Level Root Cause], 'Calendar'[Start of Month])
)
 
 
LowerLevelRootCauseRank =
RANKX(
    ALLSELECTED('Outcomes Testing Data'[Lower Level Root Cause]),
    CALCULATE(
        COUNTROWS('Outcomes Testing Data'),
        ALLEXCEPT('Outcomes Testing Data', 'Outcomes Testing Data'[Lower Level Root Cause], 'Calendar'[Start of Month])
    ) * 1000000 +
    MAX('Outcomes Testing Data'[Lower Level Root Cause UniqueID]) +
    MAX('Outcomes Testing Data'[RandomValue]),
    ,
    DESC,
    DENSE
)

 

 

RandomValue = RAND()

And this is the output:

AC23VM_0-1739972219424.png

 

I added the slicer to point out, it works if I apply all dates - it shows 1-5.  But if I try to look per month, it's full of ties.  I tried to fix this by including the calendar into parts of the formulae, but I might have it wrong.

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @AC23VM ,

 

The issue with RANKX ties when filtering by month is likely caused by the interaction between ALLSELECTED, ALLEXCEPT, and the Calendar table. Your current approach attempts to break ties by incorporating a random number and a unique ID, but it doesn’t fully respect the monthly filter context. The solution is to modify the ranking measure to explicitly ensure that RANKX evaluates only the relevant month’s data.

A better approach is to refine the RANKX function by filtering within the selected month. This can be done by applying a FILTER function within ALLSELECTED, ensuring that only data corresponding to the selected Start of Month is considered. The updated measure is:

LowerLevelRootCauseRank =
VAR CurrentCount = 
    CALCULATE(
        COUNTROWS('Outcomes Testing Data'),
        ALLEXCEPT('Outcomes Testing Data', 'Outcomes Testing Data'[Lower Level Root Cause], 'Calendar'[Start of Month])
    )
VAR TieBreaker = 
    MAX('Outcomes Testing Data'[Lower Level Root Cause UniqueID]) +
    MAX('Outcomes Testing Data'[RandomValue])

RETURN
    RANKX(
        FILTER(
            ALLSELECTED('Outcomes Testing Data'),
            'Outcomes Testing Data'[Lower Level Root Cause] IN VALUES('Outcomes Testing Data'[Lower Level Root Cause])
                && 'Calendar'[Start of Month] IN VALUES('Calendar'[Start of Month])
        ),
        CurrentCount * 1000000 + TieBreaker,
        ,
        DESC,
        DENSE
    )

This modification ensures that ranking is performed only within the selected month by applying VALUES('Calendar'[Start of Month]) within the FILTER function. This approach allows RANKX to consider only the entries corresponding to the currently filtered month, eliminating unwanted ties while maintaining ranking consistency. The tie-breaking component, which sums the unique ID and a random value, helps avoid duplicate ranks for entries with the same count.

 

Best regards,

Thanks for this @DataNinja777 

I'm getting this error, where it can't find that column, which of course exists:

AC23VM_0-1739976749852.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.