ITERATE through all records Workflow

Hello Knime Experts,
I need some suggestions on how I can perform this iterate on KNIME.
I am thinking add index would be the go-to but I cannot wrap my head around a formula. Hoping that someone can share their knowledge.

The Algorithm set:

  1. Initialization:
    NET = ORD QTY
    Virtual Backlog = ORD QTY – DELVRY QTY
  2. Remaining steps:
    NET = (NEXT) ORD QTY – Virtual Backlog
  • IF (NET DEMAND < 0)
    NET DEMAND = 0
    Virtual Backlog = NET + Virtual Backlog - DELVRY QTY

Out come i want to achive:
image
Iterate Workflow.knwf (7.0 KB)

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. :wink: )

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

2 Likes

So Net is the max(order-ship,0) and virtual back is a moving aggregator cumulative?

@takbb Thank you so much for the quick response and sorry for the confusion on different name. But your assumption is correct :slight_smile:
This works. :hand_with_index_finger_and_thumb_crossed:
However, my bad i forgot to add another requirement is *ITERATE through all records for each combination of SKU, Door and Date.
=> “previousVirtualBacklog" should be reset to 0 when I have a new cobination of SKU, Door and Date.


Iterate Workflow1.knwf (35.2 KB)

Hi @bbui226 , the simplest way of fixing that is to put the Java snippet inside a group loop (so just add a group loop start and a loop end either side of the snippet, and have the group loop configured to group on the set of “combination” fields you mentioned.

@takbb i got it right :innocent:
Thank you for spending time answering my questions about the workflow :pray:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.