Transformation of Multicolumns

KarthickDijo

New Member
Joined
Sep 14, 2022
Messages
28
Office Version
  1. 2019
Platform
  1. Windows
Hi All,

How can the 8 columns be transferred to two columns as shown in the attachment. XL2BB isn't working on my side, so attaching in image format.

Thanks in advance !!
 

Attachments

  • Input_Example.jpg
    Input_Example.jpg
    40.8 KB · Views: 12
  • Output_Example.jpg
    Output_Example.jpg
    35.1 KB · Views: 12

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello,

You'll have to put the headers in yourself... but here is a rough outline.

VBA Code:
Sub assimilate_V1()
    For i = 1 To 8 Step 2
        Cells(2, 10).Offset(Cells(Rows.Count, 10).End(3).Row - 1).Resize(Cells(Rows.Count, i).End(3).Row, 2).Value = Cells(2, i).Resize(Cells(Rows.Count, i).End(3).Row, 2).Value
    Next i
End Sub
 
Upvote 0
VBA Code:
Sub assimilate_V1()
    For i = 1 To 8 Step 2
        rnk = rnk + 1
        Cells(2, 12).Offset(Cells(Rows.Count, 10).End(3).Row - 1).Resize(Cells(Rows.Count, i).End(3).Row - 1).Value = rnk
        Cells(2, 10).Offset(Cells(Rows.Count, 10).End(3).Row - 1).Resize(Cells(Rows.Count, i).End(3).Row, 2).Value = Cells(2, i).Resize(Cells(Rows.Count, i).End(3).Row, 2).Value
    Next i
End Sub
Revision to add Rank as in your example image
 
Upvote 0
I'm rubbish at PQ.. maybe someone well-versed at PQ can help :)
Probably not so elegant, but here is one PQ solution.

Merge the four pairs of columns using a suitable delimiter, e.g. Colour§Red, Brand§Nokia.
Merge these four columns into one using another delimiter, eg. Colour§Red$Brand§Nokia.
Split this column into rows by $.
Finally, split the column into new columns by §.
 
Upvote 0
Probably not so elegant, but here is one PQ solution.

Merge the four pairs of columns using a suitable delimiter, e.g. Colour§Red, Brand§Nokia.
Merge these four columns into one using another delimiter, eg. Colour§Red$Brand§Nokia.
Split this column into rows by $.
Finally, split the column into new columns by §.
Sorry and Thanks a lot for the solution.. It's working !! Just one thing i need that rank as well.
 
Last edited:
Upvote 0
A bit long winded but see if this works for you

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Merged Columns" = Table.CombineColumns(Source,{"Name1", "Value1"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged1"),
    #"Merged Columns1" = Table.CombineColumns(#"Merged Columns",{"Name2", "Value2"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged2"),
    #"Merged Columns2" = Table.CombineColumns(#"Merged Columns1",{"Name3", "Value3"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged3"),
    #"Merged Columns3" = Table.CombineColumns(#"Merged Columns2",{"Name4", "Value4"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged4"),
    #"Merged Columns4" = Table.CombineColumns(#"Merged Columns3",{"Merged1", "Merged2"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged5"),
    #"Merged Columns5" = Table.CombineColumns(#"Merged Columns4",{"Merged5", "Merged3", "Merged4"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged6"),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Merged Columns5", {{"Merged6", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Merged6"),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Merged6", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Merged6.1", "Merged6.2"}),
    #"Sorted Rows" = Table.Sort(#"Split Column by Delimiter1",{{"Merged6.1", Order.Ascending}}),
    #"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each ([Merged6.2] <> "")),
    #"Replaced Value" = Table.ReplaceValue(#"Filtered Rows","","Location",Replacer.ReplaceValue,{"Merged6.1"}),
    #"Sorted Rows1" = Table.Sort(#"Replaced Value",{{"Merged6.1", Order.Ascending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows1", "Custom", each if[Merged6.1]= "Color" then 1 else if [Merged6.1]= "Brand" then 2 else if [Merged6.1]="Location" then 3 else 4),
    #"Sorted Rows2" = Table.Sort(#"Added Custom",{{"Custom", Order.Ascending}})
in
    #"Sorted Rows2"
 
Upvote 0
Solution
A bit long winded but see if this works for you

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Merged Columns" = Table.CombineColumns(Source,{"Name1", "Value1"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged1"),
    #"Merged Columns1" = Table.CombineColumns(#"Merged Columns",{"Name2", "Value2"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged2"),
    #"Merged Columns2" = Table.CombineColumns(#"Merged Columns1",{"Name3", "Value3"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged3"),
    #"Merged Columns3" = Table.CombineColumns(#"Merged Columns2",{"Name4", "Value4"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged4"),
    #"Merged Columns4" = Table.CombineColumns(#"Merged Columns3",{"Merged1", "Merged2"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged5"),
    #"Merged Columns5" = Table.CombineColumns(#"Merged Columns4",{"Merged5", "Merged3", "Merged4"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged6"),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Merged Columns5", {{"Merged6", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Merged6"),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Merged6", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Merged6.1", "Merged6.2"}),
    #"Sorted Rows" = Table.Sort(#"Split Column by Delimiter1",{{"Merged6.1", Order.Ascending}}),
    #"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each ([Merged6.2] <> "")),
    #"Replaced Value" = Table.ReplaceValue(#"Filtered Rows","","Location",Replacer.ReplaceValue,{"Merged6.1"}),
    #"Sorted Rows1" = Table.Sort(#"Replaced Value",{{"Merged6.1", Order.Ascending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows1", "Custom", each if[Merged6.1]= "Color" then 1 else if [Merged6.1]= "Brand" then 2 else if [Merged6.1]="Location" then 3 else 4),
    #"Sorted Rows2" = Table.Sort(#"Added Custom",{{"Custom", Order.Ascending}})
in
    #"Sorted Rows2"
Thanks a lot !!
 
Upvote 0

Forum statistics

Threads
1,223,574
Messages
6,173,141
Members
452,501
Latest member
musallam

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