Forum Discussion
bbbt123
6 years agoHelper I
data transformation in power query
Hi, I need to transform data as per example below: Table is: +----+------+
| Id | Name |
+----+------+
| 1 | aaa |
| 1 | bbb |
| 1 | ccc |
| 1 | ddd |
| 1 | eee |
+----+------+ R...
- 6 years ago
- Group your data by the first column, and for the aggregation use the ALL ROWS aggregation and call it "AllRows"
- Add a custom column, call it Names, and use Table.Column([AllRows], "Name") as the formula.
- Expand the new Names column but as Values (not rows) and select the comma as your delimiter.
- Select the ID and Names column and remove other columns.
Full M query (my data came from an Excel table which explains the source)
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Name", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Id"}, {{"AllRows", each _, type table [Id=number, Name=text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Names", each Table.Column([AllRows], "Name")), #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Names", each Text.Combine(List.Transform(_, Text.From), ","), type text}), #"Removed Other Columns" = Table.SelectColumns(#"Extracted Values",{"Id", "Names"}) in #"Removed Other Columns"
edhans
6 years agoCommunity Champion
- Group your data by the first column, and for the aggregation use the ALL ROWS aggregation and call it "AllRows"
- Add a custom column, call it Names, and use Table.Column([AllRows], "Name") as the formula.
- Expand the new Names column but as Values (not rows) and select the comma as your delimiter.
- Select the ID and Names column and remove other columns.
Full M query (my data came from an Excel table which explains the source)
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Name", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Id"}, {{"AllRows", each _, type table [Id=number, Name=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Names", each Table.Column([AllRows], "Name")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Names", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Other Columns" = Table.SelectColumns(#"Extracted Values",{"Id", "Names"})
in
#"Removed Other Columns"
bbbt123
6 years agoHelper I
Thank you 😄