Is there another way that has less steps

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
Wondering if there is a way to do what i want to do with fewer steps

Starting Table
Book2
AB
1Column 1Product±Color
2Store 1Avocado±Red Banana±Pink
3Store 2Bilberry±Orange Blackberry±Yellow Blackcurrant±Purple
Sheet3


Table I want

Book2
ABC
1Column 1ProductColor
2Store 1Avocado BananaRed Pink
3Store 2Bilberry Blackberry BlackcurrantOrange 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"
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
tried using Text to columns before importing table to PQ but not much shorter
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column 1", type text}, {"Product±Color", type text}, {"Column1", type text}, {"Column2", type text}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"Product±Color", "Column1", "Column2"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Only Selected Columns",{"Attribute"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Value", Splitter.SplitTextByDelimiter("±", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value.1", type text}, {"Value.2", type text}})
in
    #"Changed Type1"

Book1
ABCD
1Column 1Product±ColorColumn1Column2
2Store 1Avocado±RedBanana±Pink
3Store 2Bilberry±OrangeBlackberry±YellowBlackcurrant±Purple
4
5
6Column 1Value.1Value.2
7Store 1AvocadoRed
8Store 1BananaPink
9Store 2BilberryOrange
10Store 2BlackberryYellow
11Store 2BlackcurrantPurple
Sheet1
 
Upvote 0
Power Query:
let
    Source = #table({"Column 1", "Product±Color"}, {{"Store 1","Avocado±Red
Banana±Pink"},{"Store 2","Bilberry±Orange
Blackberry±Yellow
Blackcurrant±Purple"}}),
    tbl = Table.RenameColumns(Source,{{"Product±Color", "Product"}}),
    tbl1 = Table.TransformColumns(tbl, {"Product", each List.Combine(List.Transform(Text.Split(_, "#(lf)"), (x)=>Text.Split(x, "±")))}),
    tbl2 = Table.TransformColumns(Table.DuplicateColumn(tbl1, "Product", "Color"),
            {{"Product", each Text.Combine(List.Alternate(_,1,1,1),"#(lf)")}, {"Color", each Text.Combine(List.Alternate(_,1,1),"#(lf)")}})
in
    tbl2
 
Upvote 0
Solution

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top