#83 - Early-Terminated Accumulation
Problem description & analysis:
Here below is an inventory data table:
Task: We know that the quantity of this product sold today is 50, and want to calculate the new inventory data (subtract the inventory quantity in turn according to the order in the table until 50 are subtracted in total, and keep only the rows with inventory quantity greater than 0).
Solution:
Use SPL XLL and enter the following code:
A | |
1 | \=E(‘A1:D18’) |
2 | \=A1.iterate((a=min(Quantity, |
3 | return A1.select(Quantity>0) |
A2: Use iterate to loop the iteration, the ~~ in the loop represents the result of the last iteration, and its initial value is set to 50. Take the minimum value of the quantity of the current row and ~~, and assign the value to the variable a; subtract a from the quantity of the current row, and take ~~-a as the result of this iteration; When the iteration result ~~ is 0, terminate the iteration.
A3: Select the rows with quantity>0 in A1 after iteration.
The results are shown below:
Download esProc Desktop for FREE and make data work for you!!! 🚀🔥⬇️
✨SPL download address: esProc Desktop FREE Download
✨Plugin Installation Method: SPL XLL Installation and Configuration
✨References to other rich Excel operation cases: Desktop and Excel Data Processing Cases
✨YouTube FREE courses: SPL Programming
Subscribe to my newsletter
Read articles from esProc Desktop directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
esProc Desktop
esProc Desktop
esProc Desktop is a desktop data processing & analytics tool and is specifically designed for ordinary business people. It supports complex computations & spreadsheet data manipulation, can deal with tasks that are hard to accomplish in Excel, and in addition, generates more concise code than VBA and Python. esProc Desktop boasts all-around programming capabilities, supports multi-step interactive data analytics and is easy to use without configurations. This significantly lowers the technical threshold for data analytics.