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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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...
amitchandak
Super User
Super User

@Anonymous m refer how to use tiebreaker in rank

https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.