Forum Discussion
Combine duplicate rows into a single row based on ID column
Hello, I am just wondering if the below transformation is possible using Power Query Editor. If yes, then what solution would you have in mind?
Thanks
Hi Anonymous ,
Not certain why you need to achieve this but perhaps you can try like:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIsKMhJLQYyDPSMDJRidXCJGgE5AamJRRBBY4igMZDjlJgHhBBhU9zCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Product = _t, Price = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Product", type text}, {"Price", type number}}), #"Removed Duplicates" = Table.Distinct(#"Changed Type", {"ID"}), #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "duplicate", each [#"Product" = [Product],#"Price" = [Price] ]), #"Expanded duplicate" = Table.ExpandRecordColumn(#"Added Custom", "duplicate", {"Product", "Price"}, {"duplicate.Product", "duplicate.Price"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded duplicate",{{"ID", Int64.Type}, {"Product", type text}, {"Price", type number}, {"duplicate.Product", type text}, {"duplicate.Price", type number}}) in #"Changed Type1"Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- v-yingjlCommunity Support
Hi Anonymous ,
Not certain why you need to achieve this but perhaps you can try like:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIsKMhJLQYyDPSMDJRidXCJGgE5AamJRRBBY4igMZDjlJgHhBBhU9zCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Product = _t, Price = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Product", type text}, {"Price", type number}}), #"Removed Duplicates" = Table.Distinct(#"Changed Type", {"ID"}), #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "duplicate", each [#"Product" = [Product],#"Price" = [Price] ]), #"Expanded duplicate" = Table.ExpandRecordColumn(#"Added Custom", "duplicate", {"Product", "Price"}, {"duplicate.Product", "duplicate.Price"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded duplicate",{{"ID", Int64.Type}, {"Product", type text}, {"Price", type number}, {"duplicate.Product", type text}, {"duplicate.Price", type number}}) in #"Changed Type1"Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - KNPSuper User
I assume the first screenshot is your input, the second is desired result?
If so, what is the purpose of this as it looks like it goes against all best practices for data modelling?