let
Source = Excel.CurrentWorkbook(){[Name="Tableau1"]}[Content],
AddColumn_Index = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
AddColumn_MontantSigné = Table.AddColumn(AddColumn_Index, "Montant signé", each [Débit]-[Crédit], type number),
listMontantSignés = List.Buffer(AddColumn_MontantSigné[Montant signé]),
AddColumn_CumulProgressif = Table.AddColumn(AddColumn_MontantSigné, "Cumul progressif", each List.Sum(List.FirstN(listMontantSignés, [Index])), type number),
AddColumn_FlagZero = Table.AddColumn(AddColumn_CumulProgressif, "FlagZero", each if [Cumul progressif]=0 then [Index] else null),
FillUp_FlagZero = Table.FillUp(AddColumn_FlagZero,{"FlagZero"}),
DeleteColumn_Index = Table.RemoveColumns(FillUp_FlagZero,{"Index"}),
GroupBy_PieceFlagZero = Table.Group(DeleteColumn_Index, {"Pièce", "FlagZero"}, {{"Data", each _, type table [Jour=datetime, Pièce=text, Compte général=any, Débit=number, Crédit=number, Montant signé=number, Cumul progressif=number, FlagZero=number]}}),
AddColumn_GroupIndex = Table.AddIndexColumn(GroupBy_PieceFlagZero, "GroupIndex", 0, 1, Int64.Type),
listGroupPièce = List.Buffer(AddColumn_GroupIndex[Pièce]),
AddColumn_IdPiece = Table.AddColumn(AddColumn_GroupIndex, "ID Pièce", each let piece = [Pièce], idx = [GroupIndex] in piece & "-" & Text.From(List.Count(List.Select(List.FirstN(listGroupPièce, idx), each _ = piece)))),
SelectColumns = Table.SelectColumns(AddColumn_IdPiece,{"Data", "ID Pièce"}),
DevelopDataGroup = Table.ExpandTableColumn(SelectColumns, "Data", {"Jour", "Pièce", "Compte général", "Débit", "Crédit", "Montant signé", "Cumul progressif"}, {"Jour", "Pièce", "Compte général", "Débit", "Crédit", "Montant signé", "Cumul progressif"})
in
DevelopDataGroup