let
Source = Excel.CurrentWorkbook(){[Name="t_base"]}[Content],
cols = Table.ColumnNames(Source),
GroupBy = Table.Group(Source, List.FirstN(cols,3), {{"Tbl", each
let x = Table.Sort(_, {cols{4}, Order.Ascending})
in Table.AddColumn(x, "Total", each
let y = Record.Field(_, cols{4})
in List.Sum(Table.Column(Table.SelectRows(Table.SelectColumns(x, {cols{4}, cols{5}}),
each Record.Field(_, cols{4}) = y), cols{5})))}})[Tbl],
Result = Table.Combine(List.Transform(GroupBy, each Table.FromColumns(List.Accumulate(Table.ColumnNames(_), {},
(s,c)=> s & {List.Accumulate(Table.Column(_,c), {},
(s,c)=> s & {if List.Contains(s,c) then null else c})}),
cols & {"Total"})))
in
Result