Wondering if there is a way to do what i want to do with fewer steps
Starting Table
Table I want
My M code
Starting Table
Book2 | ||||
---|---|---|---|---|
A | B | |||
1 | Column 1 | Product±Color | ||
2 | Store 1 | Avocado±Red Banana±Pink | ||
3 | Store 2 | Bilberry±Orange Blackberry±Yellow Blackcurrant±Purple | ||
Sheet3 |
Table I want
Book2 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Column 1 | Product | Color | ||
2 | Store 1 | Avocado Banana | Red Pink | ||
3 | Store 2 | Bilberry Blackberry Blackcurrant | Orange Yellow Purple | ||
Sheet2 |
My M code
Power Query:
let
Source = #table({"Column 1", "Product±Color"}, {{"Store 1","Avocado±Red
Banana±Pink"},{"Store 2","Bilberry±Orange
Blackberry±Yellow
Blackcurrant±Purple"}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Product±Color", Splitter.SplitTextByDelimiter("#(lf)", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Product±Color"),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Product±Color", Splitter.SplitTextByDelimiter("±", QuoteStyle.Csv), {"x.1", "x.2"}),
#"Grouped Rows" = Table.Group(#"Split Column by Delimiter1", {"Column 1"}, {{"Count", each _, type table}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Product", each Text.Combine([Count][x.1],"#(lf)")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Color", each Text.Combine([Count][x.2],"#(lf)")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Count"})
in
#"Removed Columns"