let Source = Table.Combine({#"Sales Query", #"GRV Query"}), #"Sorted rows" = Table.Sort(Source, {{"Date ID", Order.Ascending}}), #"Replaced errors" = Table.ReplaceErrorValues(#"Sorted rows", {{"Units", 0}, {"Value per Unit", 0}}), #"Replaced value" = Table.ReplaceValue(#"Replaced errors", null, 0, Replacer.ReplaceValue, {"Units", "Value per Unit"}), #"Replaced value 1" = Table.ReplaceValue(#"Replaced value", #nan, 0, (value, old, new) => if Number.IsNaN(value) then new else value, {"Units", "Value per Unit"}), #"Changed column type" = Table.TransformColumnTypes(#"Replaced value 1", {{"Units", Int64.Type}, {"Value per Unit", type number}}), #"Inserted multiplication" = Table.AddColumn(#"Changed column type", "Multiplication", each [Value per Unit] * [Units], type number), #"Renamed columns" = Table.RenameColumns(#"Inserted multiplication", {{"Multiplication", "Total Value"}}), #"Grouped rows" = Table.Group(#"Renamed columns", {"Product ID"}, {{"Count", each _, type nullable table[#"Date ID" = nullable number, #"Product ID" = nullable number, Units = nullable Int64.Type, #"Value per Unit" = nullable number, Type = nullable text, #"Total Value" = number]}}), #"Added custom" = Table.AddColumn(#"Grouped rows", "Custom", each Table.AddIndexColumn([Count], "Index", 0, 1)), #"Removed other columns" = Table.SelectColumns(#"Added custom", {"Custom"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed other columns", "Custom", {"Date ID", "Product ID", "Units", "Value per Unit", "Type", "Total Value", "Index"}, {"Date ID", "Product ID", "Units", "Value per Unit", "Type", "Total Value", "Index"}), #"Changed column type 1" = Table.TransformColumnTypes(#"Expanded Custom", {{"Date ID", Int64.Type}, {"Product ID", Int64.Type}, {"Units", Int64.Type}, {"Index", Int64.Type}, {"Type", type text}, {"Value per Unit", type number}, {"Total Value", type number}}) in #"Changed column type 1"