Forum Discussion
Lyvili
2 years agoFrequent Visitor
Transform in columns (transpone, unpivot..)
Good afternoon, I am trying to solve this topic through several ways in PowerQuery. Unfortunately I could not. Could you please assist me? Thanks in advance! Original: TO BE:
- 2 years ago
Your data appears to be a single table. So:
- Split the table at the first null row
- Pivot Part 1
- Add the pivoted Part 1 to each row of Part 2
let Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{ {"Column1", type text}, {"Column2", type any}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type any}, {"Column7", type text}, {"Column8", type text}}), #"Split Table" = Table.SplitAt(#"Changed Type", List.PositionOf(#"Changed Type"[Column1],null, Occurrence.First)), Part1 = Table.SelectColumns(#"Split Table"{0}, List.FirstN(Table.ColumnNames(#"Split Table"{0}),2)), Part2 = Table.PromoteHeaders(Table.RemoveFirstN(#"Split Table"{1},1),[PromoteAllScalars=true, Culture="en-US"]), #"Pivot Part1" = Table.Pivot(Part1, Part1[Column1], "Column1","Column2"), #"Combine Part2" = Table.AddColumn(Part2, "Part1", each #"Pivot Part1", type table), #"Reordered Columns" = Table.ReorderColumns(#"Combine Part2",{"Part1", "ID", "ID A", "ID K", "ID M", "ID G", "Nivel", "Dept", "Centro"}), #"Expanded Part1" = Table.ExpandTableColumn(#"Reordered Columns", "Part1", {"Агеа de planificacion", "Fесћа", "С447 -FKA", "C447 -FKB", "С447 -FLK"}, {"Агеа de planificacion", "Fесћа", "С447 -FKA", "C447 -FKB", "С447 -FLK"}) in #"Expanded Part1"Source
Results
+
ronrsnfld
Super User
2 years agoYour data appears to be a single table. So:
- Split the table at the first null row
- Pivot Part 1
- Add the pivoted Part 1 to each row of Part 2
let
Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"Column1", type text}, {"Column2", type any}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text},
{"Column6", type any}, {"Column7", type text}, {"Column8", type text}}),
#"Split Table" = Table.SplitAt(#"Changed Type", List.PositionOf(#"Changed Type"[Column1],null, Occurrence.First)),
Part1 = Table.SelectColumns(#"Split Table"{0},
List.FirstN(Table.ColumnNames(#"Split Table"{0}),2)),
Part2 = Table.PromoteHeaders(Table.RemoveFirstN(#"Split Table"{1},1),[PromoteAllScalars=true, Culture="en-US"]),
#"Pivot Part1" = Table.Pivot(Part1, Part1[Column1], "Column1","Column2"),
#"Combine Part2" = Table.AddColumn(Part2, "Part1", each #"Pivot Part1", type table),
#"Reordered Columns" = Table.ReorderColumns(#"Combine Part2",{"Part1", "ID", "ID A", "ID K", "ID M", "ID G", "Nivel", "Dept", "Centro"}),
#"Expanded Part1" = Table.ExpandTableColumn(#"Reordered Columns", "Part1", {"Агеа de planificacion", "Fесћа", "С447 -FKA", "C447 -FKB", "С447 -FLK"}, {"Агеа de planificacion", "Fесћа", "С447 -FKA", "C447 -FKB", "С447 -FLK"})
in
#"Expanded Part1"
Source
Results
+