@ambidextrousmentally,
The Power Query Group By function handles this perfectly:
Here’s the setup:
Once that runs, it’s straightforward to add two custom columns for unit price and usage percent. Here’s the full M code:
let
Source = #"Original Data",
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Order ID", Int64.Type}, {"SOLI Quanity", Int64.Type}, {"Transaction Year", Int64.Type}, {"Transaction Month", Int64.Type}, {"Usage Quantity ", Int64.Type}, {"Revenue Amount USD", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Sales Order ID", "SOLI Quanity", "Transaction Year", "Transaction Month"}, {{"Total Usage Quantity", each List.Sum([#"Usage Quantity "]), type nullable number}, {"Total Revenue", each List.Sum([Revenue Amount USD]), type nullable number}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Unit Price", each [Total Revenue] / [Total Usage Quantity]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Unit Price", Currency.Type}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "% Usage", each [Total Usage Quantity] /[SOLI Quanity]),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"% Usage", Percentage.Type}})
in
#"Changed Type2"
I hope that’s helpful. Full solution file attached.
– Brian
eDNA Forum - Consolidated Rows Solution.pbix (24.3 KB)