How can I achieve the following logic

This is what the initial data would look like.
Capture

I want to look ONLY at row #1 and do the following: Stock-orders and the result would be identified by “gap” (maybe a new column named gap).
And then we move to row #2, if the gap of row#1 is >=0 subtract the orders of row1 from the stock of row 2 and this would be my new stock for row#2, else keep the stock of row#2 as it is
then calculate the gap for row#2 like we did for row#1, stock-orders (stock of row#2-orders of row#2 ofcourse)
and then we move to row#3
if the gap of row#2 is >=0 subtract the orders of row2 from the stock of row 3 and this would be my new stock for row#3, else keep the stock of row#3 as it is
then calculate the gap for row#3 like we did for row#2 and 1, stock-orders (stock of row#3-orders of row#3 ofcourse)
and then we keep doing the same thing if there are more rows.
I had 2 issues with doing this logic in knime; the first is going through every row individually which only the chunk loop does, the second is bringing back the gap of a row to be used in the math of the row after it and this can only be achieved by the recursive loop
but I’m note sure how to merge the 2 loops together in knime
Please let me know if you have any ideas!

Hello @lamasewidan ,

welcome in the Forum.

Please check this Forum post from the past I believe that is what you are looking for:

Good luck!

1 Like

Hello , I looked at that forum post but I’m not sure how it could be used to achieve what im looking for. The difference between my post and that forum post is that I have a column that is being updated after every row iteration. So not all columns should go through the math’s at once as the stock column is updated after every row. I hope I explained well enough for you to get the picture
@dora_gcs

Hi @lamasewidan -

It appears this is a duplicate of the discussion already going on in your other thread here:

Please continue the discussion there. I will close this thread to help keep the forum tidy.

2 Likes