Combine Columns - Keeping Reference

karmaimages

Board Regular
Joined
Oct 1, 2009
Messages
112
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I extract some information from a SharePoint list which is in the format of the following:

ReferenceName 1Name 2Name 3
123Person 1Person 2
124Person 2
125Person 1Person 2 Person 3

Is there a way using power query to create a combined column for all "Name" columns removing the blanks so this would look like the following:

ReferenceName
123Person 1
123Person 2
124Person 2
125Person 1
125Person 2
125Person 3

I need the reference to be maintained so creating a new row based on the number of named persons.

Many Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
With the Name 1 through Name 3 highlighted, you'll want to Unpivot those 3 Columns, which will give you 3 columns, your Reference, Attributes, and Value. The Attributes and Value will be the same so feel free to rename one and delete the other, but you'll achieve your desired results.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Reference", Int64.Type}, {"Name 1", type text}, {"Name 2", type text}, {"Name 3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Reference"}, "Name","Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Value"})
in
    #"Removed Columns"
 
Upvote 0
Solution
With the Name 1 through Name 3 highlighted, you'll want to Unpivot those 3 Columns, which will give you 3 columns, your Reference, Attributes, and Value. The Attributes and Value will be the same so feel free to rename one and delete the other, but you'll achieve your desired results.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Reference", Int64.Type}, {"Name 1", type text}, {"Name 2", type text}, {"Name 3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Reference"}, "Name","Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Value"})
in
    #"Removed Columns"
@johnny51981 that was exactly what I was looking for, works great thank you very much!
 
Upvote 0

Forum statistics

Threads
1,223,659
Messages
6,173,636
Members
452,525
Latest member
DPOLKADOT

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