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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Count duplicate value as rank it

Dear friend

How can i count a duplicate value and rank it as 1,2,3,... in the other column with DAX

 

Name           new column
jame1
jon1
jame2
jame3
jon2
jame4
jon3
1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We need to add an index column using Power Query Editor and create a calculate column to meet your requirement.

 

1. Create an index column.

 

C1.jpg

 

2. Then we can create a calculate column.

 

Rank column = 
RANKX(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])),'Table'[Index],,ASC,Dense)

 

C2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

View solution in original post

6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We need to add an index column using Power Query Editor and create a calculate column to meet your requirement.

 

1. Create an index column.

 

C1.jpg

 

2. Then we can create a calculate column.

 

Rank column = 
RANKX(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])),'Table'[Index],,ASC,Dense)

 

C2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

richbenmintz
Solution Sage
Solution Sage

Hi @Anonymous ,

 

I think you would be better off indexing your rows using Power Query, using the index by group pattern, you will find a couple great links here,

http://datacornering.com/how-to-create-group-index-with-power-query-or-r/ 

https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query 

 

Below please find the Power Query I used to create the index column that i think you are looking for

richbenmintz_0-1596807738461.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykrMTVXSUTJUitUBcvLzEGyIhBEyxxhJFYqECZIEUFEsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Name           " = _t, result = _t]),
    #"Removed Columns" = Table.RemoveColumns(Source,{"result"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Name           ", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Name           ", "Name"}}),
    #"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Name"}, {{"Count", each _, type table [Name=nullable text, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Ranker", each Table.AddIndexColumn([Count], "Rank", 1, 1)),
    #"Expanded Ranker" = Table.ExpandTableColumn(#"Added Custom", "Ranker", {"Rank"}, {"Ranker.Rank"})
in
    #"Expanded Ranker"

 

Hope this helps,

Richard 


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


Anonymous
Not applicable

are you trying to remove the duplicates and maintain the rank??

 

you better off to create a new table using name as a distinct 

name = distinct(tablename[name])

Dnerada_1-1596806251854.png

then use the rank funciton with tie breakers 

 

Greg_Deckler
Super User
Super User

@Anonymous - Not entirely sure I understand.

https://community.powerbi.com/t5/Quick-Measures-Gallery/To-Bleep-with-RANKX/m-p/1042520#M452

 

Also this because it handles dupes

https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Mythical-DAX-Index/td-p/1093214



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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