简体   繁体   中英

Split Four Columns without Headers into Two Rows in Power Query

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

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"

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM