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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sid-poly
Helper I
Helper I

Remove Duplicate Rows and Change unique Columns to Additional Columns based on Duplication

There is a table which has to be Changed in the Power Query with duplicate rows where few columns with unique values have to be pushed into new columns. Please find the table below for your reference

 

IDRevision NumberValueType
A1

0.1

Primary

A10.2Secondary
B20.3Primary
B20.4Secondary

 

This has to be in the output format.

 

PrimarySecondaryRevision NumberValue 1Value 2
AA10.10.2
BB20.30.4

 

Need help to implement the same in the Power Query

3 REPLIES 3
Anonymous
Not applicable

Hi @sid-poly  and @Anonymous ,

 

It's a common issue. The video below provides a workaround.

Power Query: How to collapse Multiple Rows to a Single Row - YouTube

For @sid-poly 's data, below is my M codes, you can copy and paste it into the advanced editor in Power Query for details. Or you can directly download my attachment for details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nRR0lEKSi3LLM7Mz1PwK81NSi0CioQl5pSmAumQyoJUpVidaCVHIMcQiA30QGRAUWZuYlElmowRkAxOTc7PS4HJOQFFjMByxmi6EDImqLpiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Revision Number", Int64.Type}, {"Value", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each [Type]&" Value"),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Type]), "Type", "ID"),
    #"Pivoted Column1" = Table.Pivot(#"Pivoted Column", List.Distinct(#"Pivoted Column"[Custom]), "Custom", "Value", List.Sum),
    #"Duplicated Column" = Table.DuplicateColumn(#"Pivoted Column1", "Revision Number", "Revision Number - Copy"),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Duplicated Column", {"Revision Number - Copy"}, "Attribute", "Value"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type2"),
    #"Pivoted Column2" = Table.Pivot(#"Removed Duplicates", List.Distinct(#"Removed Duplicates"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column2"

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Anonymous
Not applicable

Hi @sid-poly , I also had this issue, did you find any solutions elsewhere?

Hi @Anonymous  - No Not yet

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.