let
SourceTypeA = Table.AddColumn(Excel.CurrentWorkbook(){[Name="Tableau1"]}[Content], "Type", each "Type A", type text),
SourceTypeB = Table.AddColumn(Excel.CurrentWorkbook(){[Name="Tableau2"]}[Content], "Type", each "Type B", type text),
CumulSources = SourceTypeA & SourceTypeB,
CleanMontants = Table.TransformColumns(CumulSources,List.Transform({"DEBIT", "CREDIT"}, each {_, (val) => if val = null then 0 else Number.From(val), type number})),
GroupByClientType = Table.Group(CleanMontants, {"Client", "Type"}, {{"Montant", each List.Sum([CREDIT])-List.Sum([DEBIT]), type number}}),
PivotTypeColumns = Table.Pivot(GroupByClientType, List.Distinct(GroupByClientType[Type]), "Type", "Montant", each if List.Sum(_)=null then 0 else List.Sum(_)),
AddColumnSolde = Table.AddColumn(PivotTypeColumns, "Solde", each [Type B]-[Type A], type number)
in
AddColumnSolde