let
Source = Table.SelectColumns(TousComptes,{"COMPTE","LIGNE","MOIS","ANNEE","BUDGET REEL","DEBITCREDIT"}),
#"Lignes groupées1" = Table.Group(Source, {"COMPTE", "ANNEE", "MOIS", "LIGNE", "BUDGET REEL"}, {{"DEBITCREDIT", each List.Sum([DEBITCREDIT]), type nullable number}}),
#"Lignes filtrées" = Table.SelectRows(#"Lignes groupées1", each ([BUDGET REEL] = "BUDGET" or [BUDGET REEL] = "REEL")),
#"Texte en minuscules" = Table.TransformColumns(#"Lignes filtrées",{{"BUDGET REEL", Text.Lower, type text}}),
#"Lignes groupées" = Table.Group(#"Texte en minuscules", {"COMPTE", "LIGNE","MOIS","ANNEE"}, {{"Datas", each _[[BUDGET REEL],[DEBITCREDIT]] }}),
#"Ligne Manquante ?" = Table.TransformColumns(#"Lignes groupées",{{"Datas", each if Table.RowCount(_)=1 then Table.InsertRows(_,1,{[BUDGET REEL = if Table.FirstValue(_)="reel" then "budget" else "reel",DEBITCREDIT = 0]}) else _}}),
#"Grouperment 2" = Table.AddColumn(#"Ligne Manquante ?", "Sommer", each Table.Group([Datas], {"BUDGET REEL"}, {{"DEBITCREDIT", each List.Sum([DEBITCREDIT]), type number}})),
#"Lignes triées" = Table.Sort(#"Grouperment 2",{{"COMPTE", Order.Descending},{"LIGNE",Order.Ascending}}),
#"Insertion écart" = Table.TransformColumns( #"Lignes triées",{{"Sommer", each Table.InsertRows(_,2,{[BUDGET REEL = "Ecart",DEBITCREDIT=Number.Abs(_{[BUDGET REEL="reel"]}[DEBITCREDIT])-Number.Abs(_{[BUDGET REEL="budget"]}[DEBITCREDIT ])]})}}),
#"Sommer développé" = Table.ExpandTableColumn(#"Insertion écart", "Sommer", {"BUDGET REEL", "DEBITCREDIT"}, {"BUDGET REEL", "DEBITCREDIT"}),
#"Colonnes supprimées" = Table.RemoveColumns(#"Sommer développé",{"Datas"}),
#"Type modifié" = Table.TransformColumnTypes(#"Colonnes supprimées",{{"DEBITCREDIT", type number}})
in
#"Type modifié"