Transpose grouped values Power Query

Aldonin

New Member
Joined
Jan 27, 2012
Messages
28
Hi everyone: Important: I tried to solve this using both plain excel and Power Query since these are the only tools I can use, it would be great if the solutions/ideas consider those tools only, thank you so much!

Here it goes:

I have data structured in the following way: Left column shows a list of "Events", right column includes the dependent Participants for each event all comma-separated.

Host EventDependent Participants
Event1P1,P2,P3
Event2P7,P9

I'm trying and failing miserably to transform this table into something like the table below (I believe it's called tabular).


Host EventDependent Participants
Event1P1
Event1P2
Event1P3
Event2P7
Event2P9


Any ideas/suggestions on how I can solve this using excel or Power Query?

Thank you so much in advance!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This is straight forward enough in Power Query.

Start with converting your data into a table:

• Select any cell in your data range
• Either Insert > Table (3rd button from the left )
OR Ctrl + T​
• Click on the tab Table Design and in the white box on the far left put in the table name tbl_Events

Now still with a cell in the Table Selected:
  • Data > From Table Range
  • in PQ > Home > Advanced Editor (3rd Button from the left
  • Replace the code you find there with the code below
  • Close & Load OR Close & Load To
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="tbl_Events"]}[Content],
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Dependent Participants", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Dependent Participants.1", "Dependent Participants.2", "Dependent Participants.3"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Host Event"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Host Event", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Value", "Dependent Participants"}})
in
    #"Renamed Columns"
 
Upvote 0
FWIW, manual steps to do this:
1. Load the data into PQ.
2. Select the Dependent Participants column, and on the Transform tab choose Split Column - By delimiter
3. Choose comma for the delimiter, click the Advanced Options dropdown at the bottom and choose to split into Rows.
 
Upvote 0
Solution
@Aldonin, please use Rory's method.

Rory's posting made me revisit mine. I am very conscious of not hardcoding columns in the Query steps but still did not pick up that my Split Columns did hard code some columns.
Rory's method did not.

So apart from recommending you convert your data into a table and explicitly naming it (rather than have PQ call it Table1), please follow Rory's suggestion.
 
Upvote 0
Glad we could help. :)
 
Upvote 0

Forum statistics

Threads
1,214,383
Messages
6,119,198
Members
448,874
Latest member
Lancelots

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