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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count duplicates RANK in a matrix visual column without Power Query

Hi

 

I have a very simple visual matrix on a report page with as first column Article names (than can be filtered with a slicer) and a second colum with their Total sales. I made a third column with the ranks on the total sales that works perfectly as expected!

 

However.... i need a fourth column in DAX that for every row shows the number of times a given rank repeats. I'm searching since a week for a solution but i failed.

 

 

Thx a lot for your help

1 ACCEPTED SOLUTION

@Anonymous Why next monday :))
This is the formula:

 

# Identical Rank = 
VAR _tbl = 
    ADDCOLUMNS(
        ALLSELECTED('Table'[Article]),
        "@Rank", RANKX(ALLSELECTED('Table'[Article]), [# Total])
    )
VAR _current_rank = [Rank]
VAR _result = 
    COUNTROWS(
        FILTER(
            _tbl,
            [@Rank] = _current_rank
        )
    )
RETURN
    _result

 


And these are the other measure I created:

 

# Total = SUM('Table'[Total])

Rank = RANKX(ALLSELECTED('Table'[Article]), [# Total])

 

SpartaBI_0-1658397222365.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

12 REPLIES 12
tamerj1
Super User
Super User

Hi @Anonymous 
Here is a sample file with the proposed solution https://www.dropbox.com/t/3ndOIIvOfCavuLwa

1.png2.png

 

# Identical Ranks = 
VAR CurrentAmount = [Total]
VAR T1 = ALLSELECTED ( Sales[Article] )
VAR T2 = ADDCOLUMNS ( T1, "@Total", [Total] )
VAR T3 = SUMMARIZE ( T2, [@Total], "@Count", DISTINCTCOUNT ( Sales[Article] ) )
VAR T4 = FILTER ( T3, [@Total] = CurrentAmount )
RETURN
    SELECTCOLUMNS ( T4, "@@Count", [@Count] )

 

@Anonymous 

Sorry my mistake. Just replace it with [Total] measure I will update the original reply

@Anonymous 

By the way the code in the file is just fine. Just download it

Anonymous
Not applicable

Why did you hardcode one of the value (the 12000) of the matrix in the formula? Does that mean if the the values differ and change over time or that they are more than one duplicate rank your formula won't work anymore?

@Anonymous 
I have updated the screenshot and the code. Actually I have taken the screenshot of a table I just created to track the code but the measure is there in the shared file and the matix is based on it otherwise the results would be wrong.

SpartaBI
Community Champion
Community Champion

@Anonymous Here is a link to download the file with the solution:
Count duplicates RANK in a matrix visual column without Power Query 2022-07-21.pbix

Please be kind with what I asked in the previous message 😀


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Anonymous
Not applicable

I can't download any files at work. Can you share the DAX formula here in plain text on the forum please?

 

Be sure that if it works i will do a thumbs up next monday 😉

@Anonymous Why next monday :))
This is the formula:

 

# Identical Rank = 
VAR _tbl = 
    ADDCOLUMNS(
        ALLSELECTED('Table'[Article]),
        "@Rank", RANKX(ALLSELECTED('Table'[Article]), [# Total])
    )
VAR _current_rank = [Rank]
VAR _result = 
    COUNTROWS(
        FILTER(
            _tbl,
            [@Rank] = _current_rank
        )
    )
RETURN
    _result

 


And these are the other measure I created:

 

# Total = SUM('Table'[Total])

Rank = RANKX(ALLSELECTED('Table'[Article]), [# Total])

 

SpartaBI_0-1658397222365.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Anonymous
Not applicable

Sorry to answer so late i was kinda sick. That solves my problem indeed. The solution is purrrfect.

 

Thx a lot for your help @SpartaBI 

SpartaBI
Community Champion
Community Champion

@Anonymous I need more info.
Can you share a sample file and explain exactly what is the desired result you want to get for that file (with few examples).

Anonymous
Not applicable

See below a minimal working example:

 

52B7E453-C266-40BD-AAF0-5A3AFDD8EE07.jpeg

 

 

@Anonymous ok, preparing something 😀 and will share soon a solution. 
While you wait will appreciate your Kudos on my messages 😄 and check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas. 
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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