Hi @bbui226 , in your algorithm, I am assuming that “NET” and “NET DEMAND” are the same thing, and also that “DELVRY QTY” is “SHIP”
(It’s easier for people to understand if the same terminology is used throughout, and no assumption is made about what different terms mean. )
With the above, this is a classic use case where java snippet excels.
Iterate Workflow.knwf (11.2 KB)
Defining a variable “previousVirtualBacklog” in the “Your custom variables” section allows the value of the variable to be remembered from one row to the next.
// Your custom variables:
int previousVirtualBacklog=0; // this will be remembered for next row
The rest of the code is basically a simplified version of your algorithm, written in java:
// Enter your code here:
// NET = This ORD QTY - previous VIRTUAL BACKLOG (which is zero initialisation)
// IF NET < 0 THEN NET = 0
// VIRTUAL BACKLOG = NET - DELIVERY QTY + previous VIRTUAL BACKLOG
out_Net = c_Order - previousVirtualBacklog;
if (out_Net <0 )
{
out_Net = 0;
}
out_VirtualBacklog = out_Net + previousVirtualBacklog - c_Ship;
// remember the "previous virtual backlog" for next row
previousVirtualBacklog=out_VirtualBacklog;
For additional examples, and a discussion on this technique, see