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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Duplicate records with same ID-using formula

Hi,

I have a table like below where I want the id of the duplicate records to be same.

 

Current Data                                      

 

SnoNamevalue     
1John20
2John30
3Jill40
4Kirk50
5Kirk60

 

 Expected

SnoNamevalue
1John20
1John30
2Jill40
3Kirk50
3Kirk60

 

Thanks,

Ravi

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

Another approach in DAX.

 

RANK_SNO = 
RANKX (
    'Table',
    CALCULATE (
        MIN ( 'Table'[Sno] ),
        FILTER ( 'Table', EARLIER ( 'Table'[Name] ) = 'Table'[Name] )
    ),
    ,
    ASC,
    DENSE
)

Capture.PNG

View solution in original post

3 REPLIES 3
Eric_Zhang
Employee
Employee

Another approach in DAX.

 

RANK_SNO = 
RANKX (
    'Table',
    CALCULATE (
        MIN ( 'Table'[Sno] ),
        FILTER ( 'Table', EARLIER ( 'Table'[Name] ) = 'Table'[Name] )
    ),
    ,
    ASC,
    DENSE
)

Capture.PNG

Anonymous
Not applicable

Screenshot.PNG

Thanks Eric and Marcel , I have worked out both and works perfectly fine.

@Eric_Zhang  If I have the data without the S.no column  and  if I have the same Values for the same name in this case (John 20)would it be possible to acheive the same using RankX

, I used this but I am not getting the Correct output

 

Column = RANKX(Sheet1,
       
        Sheet1[Name]
    ,
,ASC,Dense)

 

Namevalue     
John20
John20
Jill40
Kirk50
Kirk60

 

 

MarcelBeug
Community Champion
Community Champion

Steps:

  1. Remove Sno,
  2. Group By Name with operation "All Rows",
  3. Add Index column (from 1) and give this column the name "Sno" (you can adjust the name in the generated code for the added index column),
  4. Expand "value"  from the nested table (result from group by) and
  5. Reorder the columns (I selected the columns in the desired order and then removed other columns (there are no other columns but this will result in reordering the columns in the sequnce of column selection)).

 

Code:

 

let
    Source = CurrentData,
    #"Removed Columns" = Table.RemoveColumns(Source,{"Sno"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Name"}, {{"AllData", each _, type table}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Sno", 1, 1),
    #"Expanded AllData" = Table.ExpandTableColumn(#"Added Index", "AllData", {"value"}, {"value"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded AllData",{"Sno", "Name", "value"})
in
    #"Removed Other Columns"
Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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