Please help create a function that will create additional column "remainder". This solution should calculate the remainder according to the logic illustrated in our provided screenshot, where each successive row reduces the quantity accordingly. I would be very grateful for your help (ChatGPT and Copilot can't help). Thanks
Power Query:
let
// Create Table2
SourceTable2 = Table.FromRecords({
[bul = "B8-360-0660", qty = 10],
[bul = "B8-360-0690", qty = 37],
[bul = "B8-614-0500", qty = 93],
[bul = "B8-614-0600", qty = 2],
[bul = "B8-614-0650", qty = 27],
[bul = "B8-614-0690X", qty = 2],
[bul = "B8-614-0720", qty = 23],
[bul = "B8-614-0760", qty = 32],
[bul = "B8-614-0780X", qty = 16],
[bul = "B8-614-0800", qty = 16],
[bul = "B8-614-0900", qty = 31],
[bul = "B8-614-0945", qty = 16],
[bul = "B8-614-0950", qty = 20],
[bul = "B8-614-1050", qty = 56]
}),
// Create Table1
SourceTable1 = Table.FromRecords({
[bul = "B8-510-1050", qty for = 14, iterations = 1],
[bul = "B8-510-1050", qty for = 42, iterations = 2],
[bul = "B8-614-0500", qty for = 25, iterations = 3],
[bul = "B8-614-0500", qty for = 25, iterations = 4],
[bul = "B8-614-0500", qty for = 8, iterations = 5],
[bul = "B8-614-0500", qty for = 17, iterations = 6],
[bul = "B8-614-0500", qty for = 17, iterations = 7],
[bul = "B8-614-0650", qty for = 19, iterations = 8],
[bul = "B8-360-0690", qty for = 14, iterations = 9],
[bul = "B8-614-0760", qty for = 18, iterations = 10],
[bul = "B8-614-0945", qty for = 16, iterations = 11],
[bul = "B8-614-0720", qty for = 23, iterations = 12],
[bul = "B8-614-0900", qty for = 19, iterations = 13],
[bul = "B8-614-1060", qty for = 15, iterations = 14],
[bul = "B8-614-0900", qty for = 10, iterations = 15],
[bul = "B8-614-1060", qty for = 3, iterations = 16],
[bul = "B8-307-0965", qty for = 12, iterations = 17],
[bul = "B8-307-0750", qty for = 17, iterations = 18]
}),
// Merge tables on "bul"
MergedTable = Table.NestedJoin(SourceTable1, "bul", SourceTable2, "bul", "MergedT", JoinKind.LeftOuter),
#"Expanded MergedT" = Table.ExpandTableColumn(MergedTable, "MergedT", {"bul", "qty"}, {"MergedT.bul", "MergedT.qty"})
in
#"Expanded MergedT"
Excel Formula:
[TABLE width="83pt"]
[TR]
[td width="83pt"]remainder[/td]
[/TR]
[TR]
[td]-14[/td]
[/TR]
[TR]
[td]-42[/td]
[/TR]
[TR]
[td]23[/td]
[/TR]
[TR]
[td]68[/td]
[/TR]
[TR]
[td]43[/td]
[/TR]
[TR]
[td]35[/td]
[/TR]
[TR]
[td]18[/td]
[/TR]
[TR]
[td]1[/td]
[/TR]
[TR]
[td]8[/td]
[/TR]
[TR]
[td]0[/td]
[/TR]
[TR]
[td]14[/td]
[/TR]
[TR]
[td]0[/td]
[/TR]
[TR]
[td]12[/td]
[/TR]
[TR]
[td]2[/td]
[/TR]
[TR]
[td]-15[/td]
[/TR]
[TR]
[td]-3[/td]
[/TR]
[TR]
[td]-12[/td]
[/TR]
[TR]
[td]-17[/td]
[/TR]
[/TABLE]