Hey Collier,
This is a fun setup. You can shape the date exactly the way you like with the following code:
let
Source = Excel.CurrentWorkbook(){[Name="MyData"]}[Content],
Transpose = Table.Transpose(Source),
FillDown = Table.FillDown(Transpose,{"Column1"}),
PromoteHeaders = Table.PromoteHeaders(FillDown, [PromoteAllScalars=true]),
#"Renamed Columns" = Table.RenameColumns(PromoteHeaders,{{"Column1", "Period"}}),
Add_SortColumn = Table.AddIndexColumn(#"Renamed Columns", "Index", 0, 1, Int64.Type),
Adj_IndexColumn = Table.TransformColumns(Add_SortColumn, {{"Index", each Number.IntegerDivide(_, 3), Int64.Type}}),
Unpivot = Table.UnpivotOtherColumns(Adj_IndexColumn, {"Period", "Team", "Index"}, "Attribute", "Value"),
PivotCols = Table.Pivot(Unpivot, List.Distinct(Unpivot[Team]), "Team", "Value", List.Sum),
SortRows = Table.Sort(PivotCols,{{"Index", Order.Ascending}, {"Attribute", Order.Ascending}}),
RemoveOtherCols = Table.SelectColumns(SortRows,{"Period", "Attribute", "Plan", "Actual", "Gap"}),
ChangeType = Table.TransformColumnTypes(RemoveOtherCols,{{"Plan", Int64.Type}, {"Actual", Int64.Type}, {"Gap", Int64.Type}, {"Period", type text}, {"Attribute", type text}})
in
ChangeType
To make sure the sorting remains as desired, you can include an index column. And then use the Number.IntegerDivide operation to return the relevant numbers, as described here: https://powerquery.how/number-integerdivide/
Here’s a copy of the solution file too.
PowerQuery_Example.xlsx (19.0 KB)
Hope that helps!