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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

RANKX, using a second value to break tiebreaker (TOP N returns additional rows)

After applying the TOP N filter to a table visual im left with an extra row due to a tie breaker, therefore i'm looking to create a RANKX measure using an additional value to break this tie breaker when a tie occurs.

 

picture 0.PNG

Since there is a tie when using count i would like to break the tie by using the 'Amount' Column which would place the row with 28 in the first rank, and 24 displaying Rank 2

picture 1.PNG

Thank you to everyone in advance for the help!

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

You can create this measure to calculate:

Rank =
VAR a =
    CALCULATETABLE (
        FILTER (
            DISTINCT ( 'Table'[Food] ),
            RANKX (
                ALLSELECTED ( 'Table' ),
                CALCULATE ( COUNT ( 'Table'[Heath Rating] ) ),
                ,
                DESC,
                DENSE
            ) = 1
        ),
        ALLSELECTED ()
    )
RETURN
    IF (
        CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Food] IN a ) = 0,
        BLANK (),
        RANKX (
            GROUPBY (
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Food] IN a ),
                'Table'[Heath Rating]
            ),
            CALCULATE ( SUM ( 'Table'[Amount] ), 'Table'[Food] IN a ),
            ,
            DESC,
            DENSE
        )
    )

rank.png

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
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

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

You can create this measure to calculate:

Rank =
VAR a =
    CALCULATETABLE (
        FILTER (
            DISTINCT ( 'Table'[Food] ),
            RANKX (
                ALLSELECTED ( 'Table' ),
                CALCULATE ( COUNT ( 'Table'[Heath Rating] ) ),
                ,
                DESC,
                DENSE
            ) = 1
        ),
        ALLSELECTED ()
    )
RETURN
    IF (
        CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Food] IN a ) = 0,
        BLANK (),
        RANKX (
            GROUPBY (
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Food] IN a ),
                'Table'[Heath Rating]
            ),
            CALCULATE ( SUM ( 'Table'[Amount] ), 'Table'[Food] IN a ),
            ,
            DESC,
            DENSE
        )
    )

rank.png

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahoneypat
Microsoft Employee
Microsoft Employee

Please see this article/video.

RANKX on multiple columns with DAX and Power BI - SQLBI

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.