let
a = each Excel.CurrentWorkbook(){[Name=_]}[Content],
b = (x)=> List.Transform({11,4,9,10,8}, each x{_}),
c = Table.FromRows(List.Transform(Table.ToRows(a("Table1")), (x)=> {Text.From(x{0}) & "-"
& Text.PadStart(Text.From(x{2}),2,"0")} & b(x)), {"x"} & b(Table.ColumnNames(a("Table1")))),
d = List.TransformMany( List.Buffer(List.Distinct(List.Transform(c[x], each Text.BeforeDelimiter(_,"-")))),
(x)=> let x = Table.Buffer(a("t_mois")) in List.RemoveNulls(Table.AddColumn(x, "x", (y)=>
if Record.Field(y, Table.ColumnNames(x){1}) <> null then Text.PadStart(Text.From(Table.PositionOf(x, y) + 1), 2,"0") else null)[x]), (x,y)=> x & "-" & y),
e = Table.SelectRows(c, each List.Contains(d, [x])),
f = Table.Pivot(e, List.Sort(List.Distinct(e[x]),0), "x", "Solde", List.Sum),
g = List.Accumulate(List.Sort(List.Distinct(a("Table1")[Année]),0), f, (s,c)=> Table.AddColumn(s, Text.From(c) & "-Total",
each List.Sum(Record.ToList(Record.SelectFields(_, List.Select(Table.ColumnNames(f), each Text.StartsWith(_, Text.From(c)))))))),
h = Table.SelectColumns(g, let x = Table.ColumnNames(g) in List.FirstN(x,4) & List.Sort(List.Skip(x,4), 0))
in
h