Forum Discussion
PQ - power query split multiple rows to multiple columns
- 9 years ago
Someone already did... Greg_Deckler
By the way, the not-so-easy solution with dynamic columns is in the code below.
I added a count with the grouping, added a line of code to generate column names to be used as last parameter for Table.SplitColumn added a step to remove the counts and removed the last #"Changed Type" step as the columns are text already.
let Source = Table1, #"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Count", each Table.RowCount(_), type number},{"Column2", each Text.Combine([Column2],","), type text}}), Columns = List.Transform({1..List.Max(#"Grouped Rows"[Count])}, each "Column2."&Text.From(_)), #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Column2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), Columns), #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Count"}) in #"Removed Columns" - 9 years ago
As you've pinged me in here - this would be my (dynamic) approach ;-) :
let Source = Table1, Group = Table.Group(Source, {"Column1"}, {{"All", each Table.FromRows({_[Column2]}), type table}}), #"Renamed Columns" = Table.RenameColumns(Group,{{"Column1", "Item"}}), #"Expanded All" = Table.ExpandTableColumn(#"Renamed Columns", "All", Table.ColumnNames(Table.Combine(#"Renamed Columns"[All]))) in #"Expanded All"
OK, this seems like it should be easy but I messed with it and can't get it. Perhaps ImkeF or someone better with M than I can figure it out.
- MarcelBeug9 years agoCommunity Champion
Someone already did... Greg_Deckler
By the way, the not-so-easy solution with dynamic columns is in the code below.
I added a count with the grouping, added a line of code to generate column names to be used as last parameter for Table.SplitColumn added a step to remove the counts and removed the last #"Changed Type" step as the columns are text already.
let Source = Table1, #"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Count", each Table.RowCount(_), type number},{"Column2", each Text.Combine([Column2],","), type text}}), Columns = List.Transform({1..List.Max(#"Grouped Rows"[Count])}, each "Column2."&Text.From(_)), #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Column2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), Columns), #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Count"}) in #"Removed Columns"- ImkeF9 years agoCommunity Champion
As you've pinged me in here - this would be my (dynamic) approach ;-) :
let Source = Table1, Group = Table.Group(Source, {"Column1"}, {{"All", each Table.FromRows({_[Column2]}), type table}}), #"Renamed Columns" = Table.RenameColumns(Group,{{"Column1", "Item"}}), #"Expanded All" = Table.ExpandTableColumn(#"Renamed Columns", "All", Table.ColumnNames(Table.Combine(#"Renamed Columns"[All]))) in #"Expanded All"- nirrobi9 years agoHelper V
WOW,
thanks a lot.
- nirrobi9 years agoHelper V
Thanks a lot for your help and effort !!
Nir.