I have data that looks like this:
Column1 | Column2 | Column3 | Column 4 |
---|---|---|---|
Work Order Number | 12345678-123 | Total Fee | £1,000 |
Work Order Title | A Project | Remaining Fee | £500 |
Sector | Commercial | Last Review | 01/12/22 |
And I want to re-shape that data in Power Query so it looks like the table below (Although the order of the columns isn't important).
Work Order Number | Work Order Title | Sector | Total Fee | Remaining Fee | Last Review |
---|---|---|---|---|---|
12345678-123 | A Project | Commercial | £1,000 | £500 | 01/12/22 |
Does anybody have any pointers on how to do this?
Thanks,
Chris
CodePudding user response:
Try below
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
// assumes groups of three rows
#"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 3), Int64.Type}}),
// assumes groups of 2 columns index
Part1 = Table.SelectColumns(#"Integer-Divided Column",{"Column1", "Column2", "Index"}),
Part2a = Table.SelectColumns(#"Integer-Divided Column",{"Column3", "Column4", "Index"}),
Part2b = Table.RenameColumns(Part2a,{{"Column3", "Column1"}, {"Column4", "Column2"}}),
combined=Table.Combine({Part1,Part2b}),
#"Pivoted Column" = Table.Pivot(combined, List.Distinct(combined[Column1]), "Column1", "Column2"),
#"Changed Type" = Table.TransformColumnTypes(#"Pivoted Column",{{"Last Review", type date}, {"Total Fee", type number}, {"Remaining Fee", type number}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Index"})
in #"Removed Columns"