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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Paulien_
Frequent Visitor

RANKX return blank when rank is tied

Hi,

 

I am trying to build the follow table in which the rank is calculated using the RANKX function. 

RankProduct# views
1Bike300
2Car200
 Bus200
3Train40
4Airplane 3

 

However, my rank formula returns the table below. If the ranks are the same, the rank is duplicated. I was wondering, instead of showing a duplicate rank, is it possible to show a "blank" of the same rank occurs multiple times? 

 

RankProduct# views
1Bike300
2Car200
2Bus200
3Train40
4Airplane 3


Current formulas I use:

# views = count(viewid)

Rank = RANKX(ALLSELECTED('Product'[Product]),[# views],,DESC,Dense) 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Paulien_ ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Transform the data in Power Query Editor as below screenshot: add count column and index column

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMTlXSUUoyMFSK1UHiGqFyjVG5JqhcUzDXObEIyEuGmhRSlJiZB+SXQPmOmUUFOYl5IA2JUCGYBiMUHtSq0mKQ0aUwd8G4RqhcYzS7gNKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, viewid = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"viewid", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"viewid", each _, type table [Product=nullable text, viewid=nullable text]}}),
    #"Expanded viewid" = Table.ExpandTableColumn(#"Grouped Rows", "viewid", {"viewid"}, {"viewid"}),
    #"Sorted Rows" = Table.Sort(#"Expanded viewid",{{"Count", Order.Descending}}),
    #"Grouped Rows1" = Table.Group(#"Sorted Rows", {"Count", "Product"}, {{"Details", each _, type table [Product=nullable text, Count=number, viewid=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows1", "Index", 1, 1, Int64.Type),
    #"Expanded Details" = Table.ExpandTableColumn(#"Added Index", "Details", {"viewid"}, {"viewid"})
in
    #"Expanded Details"

yingyinr_1-1651735858085.png

2. Create a calculated column as below

Rank = 
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Product'[Product] ),
        FILTER ( 'Product', 'Product'[Count] = EARLIER ( 'Product'[Count] ) )
    )
VAR _minindex =
    CALCULATE (
        MIN ( 'Product'[Index] ),
        FILTER ( 'Product', 'Product'[Count] = EARLIER ( 'Product'[Count] ) )
    )
VAR _rank =
    RANKX ( 'Product', 'Product'[Count],, DESC, DENSE )
RETURN
    IF ( 'Product'[Index] <> _minindex, BLANK (), _rank )

yingyinr_0-1651735759703.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Paulien_ ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Transform the data in Power Query Editor as below screenshot: add count column and index column

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMTlXSUUoyMFSK1UHiGqFyjVG5JqhcUzDXObEIyEuGmhRSlJiZB+SXQPmOmUUFOYl5IA2JUCGYBiMUHtSq0mKQ0aUwd8G4RqhcYzS7gNKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, viewid = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"viewid", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"viewid", each _, type table [Product=nullable text, viewid=nullable text]}}),
    #"Expanded viewid" = Table.ExpandTableColumn(#"Grouped Rows", "viewid", {"viewid"}, {"viewid"}),
    #"Sorted Rows" = Table.Sort(#"Expanded viewid",{{"Count", Order.Descending}}),
    #"Grouped Rows1" = Table.Group(#"Sorted Rows", {"Count", "Product"}, {{"Details", each _, type table [Product=nullable text, Count=number, viewid=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows1", "Index", 1, 1, Int64.Type),
    #"Expanded Details" = Table.ExpandTableColumn(#"Added Index", "Details", {"viewid"}, {"viewid"})
in
    #"Expanded Details"

yingyinr_1-1651735858085.png

2. Create a calculated column as below

Rank = 
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Product'[Product] ),
        FILTER ( 'Product', 'Product'[Count] = EARLIER ( 'Product'[Count] ) )
    )
VAR _minindex =
    CALCULATE (
        MIN ( 'Product'[Index] ),
        FILTER ( 'Product', 'Product'[Count] = EARLIER ( 'Product'[Count] ) )
    )
VAR _rank =
    RANKX ( 'Product', 'Product'[Count],, DESC, DENSE )
RETURN
    IF ( 'Product'[Index] <> _minindex, BLANK (), _rank )

yingyinr_0-1651735759703.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Paulien_
Frequent Visitor

Thank you for your suggestion, unfortunately the mentioned tie breaker is not what I need.

amitchandak
Super User
Super User

@Paulien_ , I would suggest to use tie breaker instead of making it blank

Rank Tie breaker
https://community.powerbi.com/t5/Community-Blog/Breaking-Ties-in-Rankings-with-RANKX-Using-Multiple-...
https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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