Create a function

slava1857

New Member
Joined
Nov 13, 2024
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
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]
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top