Merge Duplicate Row Data into Multiple Columns

jamobe

New Member
Joined
Dec 23, 2014
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Greetings fellow excel enthusiasts.

I'm really stuck with this problem, as in the below example I am trying to get my data onto 1 row. Have followed a few power query tutorials on here and on youtube but cannot get it to work as some of my SKUs are text and numbers. So when editing the Text.Combine code, it still resulted in errors.

Basically trying to get the data in the 1st table below to be like the 2nd table with multiple columns for their images. Even just getting the images merged with a delimiter would be good. Ideally I would like to keep the Sort order the same also. Any help would be much appreciated. Thanks

SKUImageIs MainSort Order
445511​
Image A
TRUE​
0​
7226694​
Image A
TRUE​
0​
7226694​
Image B
FALSE​
1​
7226694​
Image C
FALSE​
2​
7226694​
Image D
FALSE​
3​
7226694​
Image E
FALSE​
4​
7228970​
Image A
TRUE​
0​
7229037​
Image A
TRUE​
0​
7229037​
Image B
FALSE​
1​
7229037​
Image C
FALSE​
2​

SKUImage 1Image 2Image 3Image 4Image 5
445511​
Image A
7226694​
Image AImage BImage CImage DImage E
7228970​
Image A
7229037​
Image AImage BImage C
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How about this?

Book1
ABCDEF
1SKUImage.1Image.2Image.3Image.4Image.5
2445511Image A
37226694Image AImage BImage CImage DImage E
47228970Image A
57229037Image AImage BImage C
Table1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"SKU"}, {{"Image", each _, type table [SKU=text, Image=text, Is Main=text, Sort Order=any]}}),
    Combine = Table.TransformColumns(Group,{{"Image", each Text.Combine(_[Image],",")}}),
    Split = Table.SplitColumn(Combine, "Image", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Image.1", "Image.2", "Image.3", "Image.4", "Image.5"})
in
    Split
 
Upvote 0
Solution
Hi

Thanks, I actually have just been reading a similar response you left on another thread, also using a transpose formula. I cannot seem to get that code above to work, I am copy and pasting it into the formula part of power query. Not sure what to do with the code after that tbh
 
Upvote 0
Load the data into Power Query, then click on the 'Advanced Editor' button and paste the code there. Also, make sure that your table name matches the table name in the code. I.E. make sure the table is actually named Table1.
 
Upvote 0
Sorry, I never placed the = at start! Works perfectly, thanks very much. The code looks the exact same way as the methods I was going by on the tutorials, but I just couldn't for the life of me get it to work
 
Upvote 0
The code before works on the example, but this version will be more dynamic. For example, if you added another row for SKU 7226694 with 'Image F', it won't show up. This code below will accommodate more entries.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"SKU"}, {{"Image", each _, type table [SKU=text, Image=text, Is Main=text, Sort Order=any]}}),
    Combine = Table.TransformColumns(Group,{{"Image", each Text.Combine(_[Image],",")}}),
    Split = Table.SplitColumn(Combine, "Image", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), 
        List.Generate(()=>1, each _ < List.Count(List.Distinct(Source[Image]))+1, each _ + 1, each "Image " & Text.From(_))
    )
in
    Split
 
Upvote 0
The code before works on the example, but this version will be more dynamic. For example, if you added another row for SKU 7226694 with 'Image F', it won't show up. This code below will accommodate more entries.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"SKU"}, {{"Image", each _, type table [SKU=text, Image=text, Is Main=text, Sort Order=any]}}),
    Combine = Table.TransformColumns(Group,{{"Image", each Text.Combine(_[Image],",")}}),
    Split = Table.SplitColumn(Combine, "Image", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv),
        List.Generate(()=>1, each _ < List.Count(List.Distinct(Source[Image]))+1, each _ + 1, each "Image " & Text.From(_))
    )
in
    Split
That's great. thanks for your help, much appreciated
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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