Forum Discussion
cool_333
3 years agoFrequent Visitor
Help with power query
Hi, guys need help with power query transformation below is the raw data that need the output as 2nd table. Thanks in advance. Raw data
ronrsnfld
3 years agoSuper User
Another approach is, after unpivoting, group by the first five columns, and aggregate by pivoting each subtable
let
//Change next line to reflect actual data source
Source = Excel.CurrentWorkbook(){[Name="Table24"]}[Content],
//set data types
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"ProjectRef", type text}, {"ModelDataset", type text}, {"ProjectStart", type date},
{"ProjectEnd", type date}, {"FacilitiesUnitRate", Int64.Type},
{"FacilitiesQuantity", Int64.Type}, {"ServiceUnitRate", Int64.Type},
{"ServiceQuantity", Int64.Type}}),
//Unpivot the Rate and Quantity columns
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type",
{"ProjectRef", "ModelDataset", "ProjectStart", "ProjectEnd"}, "Attribute", "Value"),
//Split the Attribute Column retaining the first lower to upper case transition
// and label appropriately
#"Split Column by Character Transition" =
Table.SplitColumn(#"Unpivoted Columns", "Attribute",
Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}),
{"Category", "Attribute"}),
//Group rows by the first five columns
#"Grouped Rows" = Table.Group(#"Split Column by Character Transition",
{"ProjectRef", "ModelDataset", "ProjectStart", "ProjectEnd", "Category"}, {
//Aggregate by pivoting each subgroup on the Attribute column
{"Aggregate", (t)=>Table.Pivot(t,List.Distinct(t[Attribute]), "Attribute","Value"),
type table[Unit=Currency.Type, Quantity=Int64.Type]}
}),
//Expand the Tables column
#"Expanded Aggregate" = Table.ExpandTableColumn(#"Grouped Rows", "Aggregate", {"Unit", "Quantity"}, {"Unit Rate", "Quantity"})
in
#"Expanded Aggregate"