How can I turn this excel table
Country | Initiative | Staff involved | Billing hours |
---|---|---|---|
HK | Data Lake | Amy, Ben, Li | 6,3,8 |
into this using Excel/ Python/ Power query? (not necessarily 3 staffs, can more more or less)
Country | Initiative | Staff involved | Billing hours |
---|---|---|---|
HK | Data Lake | Amy | 6 |
HK | Data Lake | Ben | 3 |
HK | Data Lake | Li | 8 |
You could do this using Power Query from Excel by following these steps.
Select the data and go to Data>Get & Transform Data.
Select the From Sheet option, make sure My table has headers is checked and click OK.
In Power Query go to Add Column>Custom Column and use this for the Custom column formula.
= Text.Split([Staff involved], ",")
= Text.Split([Billing Hours], ",")
= Table.FromColumns({[Custom], [Custom.1]})
Now you can expand the last custom column to get the data you want.
Finally delete the unneeded columns, rename the other columns as required and go to File>Close and Load to return the data to Excel.
Here is the full M code generated when following the above steps.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Split([Staff involved], ",")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Split([Billing hours], ",")),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each Table.FromColumns({[Custom], [Custom.1]})),
#"Expanded Custom.2" = Table.ExpandTableColumn(#"Added Custom2", "Custom.2", {"Column1", "Column2"}, {"Custom.2.Column1", "Custom.2.Column2"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.2",{"Staff involved", "Billing hours", "Custom", "Custom.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.2.Column1", "Staff Involved"}, {"Custom.2.Column2", "Billing Hours"}})
in
#"Renamed Columns"