let
Source = Excel.CurrentWorkbook(){[Name = "Tabela1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"Station", Int64.Type}, {"Amount", Int64.Type}, {"Units", Int64.Type}, {"Cost", type number}}
),
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"Station"},
{
{"tbl", each _, type table},
{"Amount", each List.Sum([Amount]), type nullable number},
{"Units", each List.Sum([Units]), type nullable number},
{"Cost", each List.First([Cost]), type nullable number}
}
),
#"Added Custom" = Table.AddColumn(
#"Grouped Rows",
"Tables",
each Table.Combine(
{
[tbl],
Table.FromRecords(
{Record.RemoveFields(_, "tbl") & [Station = Text.From([Station]) & " Total"]}
)
}
)
),
Grand = Table.Group(
#"Changed Type",
{},
{
{"Station", each "Grand Total", type nullable text},
{"Amount", each List.Sum([Amount]), type nullable number},
{"Units", each List.Sum([Units]), type nullable number},
{"Cost", each List.First([Cost]), type nullable number}
}
),
Result = Table.Combine(#"Added Custom"[Tables] & {Grand})
in
Result