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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
CHARLEA1
Frequent Visitor

Identifying Duplicates and Ranking using Power Query

Hi there, 
I've spent a long time searching the internet and have only found forumns on how to accomplish this via DAX, although I need a solution on Power Query as I intend to pivot the table depending on the custom column results.
I'm looking for how I can count a duplicate value and rank it as 1,2,3,... in the other column with Power Query

Eg. 

Name           new column
jame1
jon1
jame2
jame3
jon2
jame4
jon3

 

Any help would be much appreciated!

Thanks,
Ashling

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello - you can accomplish this by: grouping > add an index for each row > add another index to the grouped table in each row > expand.

 

jennratten_0-1647998015581.png

SCRIPT:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFOK1UFiBCcWJeJg+JQmV6IxMnNygKxYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Names", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Names"}, {{"Data", each _, type table [Names=nullable text, Index=number]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Subtable", each Table.AddIndexColumn ([Data], "Index2", 1, 1, Int64.Type )),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Subtable", "Index"}),
    #"Expanded Subtable" = Table.ExpandTableColumn(#"Removed Other Columns", "Subtable", {"Names", "Index2"}, {"Names", "Index2"})
in
    #"Expanded Subtable"

View solution in original post

2 REPLIES 2
wdx223_Daniel
Community Champion
Community Champion

NewStep=Table.FromRecords(List.Accumulate(Table.ToRecords(PreviousStepName),{{},[]},(x,y)=>let a=Record.TransformFields(x{1},{y[Name],each _+1??1}) in {x{0}&{y&[Count=Record.Field(a,y[Name])]}},a}){0})

jennratten
Super User
Super User

Hello - you can accomplish this by: grouping > add an index for each row > add another index to the grouped table in each row > expand.

 

jennratten_0-1647998015581.png

SCRIPT:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFOK1UFiBCcWJeJg+JQmV6IxMnNygKxYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Names", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Names"}, {{"Data", each _, type table [Names=nullable text, Index=number]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Subtable", each Table.AddIndexColumn ([Data], "Index2", 1, 1, Int64.Type )),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Subtable", "Index"}),
    #"Expanded Subtable" = Table.ExpandTableColumn(#"Removed Other Columns", "Subtable", {"Names", "Index2"}, {"Names", "Index2"})
in
    #"Expanded Subtable"

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.