let
Source = Table.SelectColumns(Excel.CurrentWorkbook(){[Name="TAB_COMPTES"]}[Content],{"COMPTE","LIGNE","BUDGET REEL","DEBITCREDIT","ANNEE","MOIS","BQ"}),
#"Lignes filtrées" = Table.SelectRows(Source, each ([BQ] = "oui" or [BQ] = "OUI")),
Partitions = Table.Partition(#"Lignes filtrées","BUDGET REEL",2,each Number.From(_="REEL")),
Transformation = List.Transform(List.Zip({{"BUDGET","REEL"},Partitions}),each let LaTable = Table.Group(_{1}, {"COMPTE","ANNEE","MOIS","LIGNE"}, {{"DEBITCREDIT", each List.Sum([DEBITCREDIT]), type number}}) in Table.RenameColumns(LaTable,{"DEBITCREDIT",_{0}}) ),
Jointure = Table.Join(Transformation{0},{"COMPTE","ANNEE","MOIS","LIGNE"},Transformation{1},{"COMPTE","ANNEE","MOIS","LIGNE"}),
#"Ecart calculé" = Table.AddColumn(Jointure, "Ecart", each Number.Abs([REEL])-Number.Abs([BUDGET]), type number),
Pivoter = Table.UnpivotOtherColumns(#"Ecart calculé", {"COMPTE","ANNEE","MOIS","LIGNE"}, "Attribut", "Valeur"),
#"Colonnes renommées" = Table.RenameColumns(Pivoter,{{"Attribut", "Budget Reel"}, {"Valeur", "DEBIT CREDIT"}})
in
#"Colonnes renommées"