# how to use recursive and chunk loop in the same time

**URL:** <https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518>\
**Category:** KNIME Analytics Platform\
**Created:** [July 27, 2022, 9:23pm UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518 "2022-07-27T21:23:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lamasewidan](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@lamasewidan](https://forum.knime.com/u/lamasewidan)\
**Post date:** [July 27, 2022, 9:23pm UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/1 "2022-07-27T21:23:18Z")

</div>

Hello,  
I want to design a loop that goes through row #1 and outputs a value that will be used in row #2. So it has to go through the rows one by one (not all at once) and bring back the data from the loop end node to the start node. So basically a combination of chunk and recursive loops. Is there a way to do this? Any ideas you may have are appreciated!

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [July 27, 2022, 10:30pm UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/2 "2022-07-27T22:30:16Z")

</div>

Hi @lamasewidan , could you share some data and show what the expected results for the first 3 lines, and of course explain how you got to these values?

This will help illustrate what you are trying to do, and there might be a more straight forward way to do this instead of using 2 loops nested in one another.

---

<div class="post-metadata">

**Author:** ![lamasewidan](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@lamasewidan](https://forum.knime.com/u/lamasewidan)\
**Post date:** [July 28, 2022, 5:25am UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/3 "2022-07-28T05:25:48Z")

</div>

Thanks for the reply! Okay this is what I want to do  
 ![Capture](https://forum-cdn.knime.com/uploads/default/original/3X/9/b/9b65f42d40b30145035b9aa9a7d1737a506a250f.png)  
This is what the initial data would look like.  
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  
thats why I initially asked how to used the 2 loops together. if there are other ways to do this please let me know!

---

<div class="post-metadata">

**Author:** ![lamasewidan](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@lamasewidan](https://forum.knime.com/u/lamasewidan)\
**Post date:** [July 28, 2022, 10:39am UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/4 "2022-07-28T10:39:45Z")

</div>

@bruno29a check reply above

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [July 28, 2022, 5:29pm UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/5 "2022-07-28T17:29:54Z")

</div>

I guess Nodes like Math Formula, Moving Aggregation or Lag could be helful here  
br

---

<div class="post-metadata">

**Author:** ![dora\_gcs](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e9c0ed/32.png) [@dora\_gcs](https://forum.knime.com/u/dora_gcs)\
**Post date:** [July 29, 2022, 9:20am UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/6 "2022-07-29T09:20:37Z")

</div>

Furthermore please check these posts they seems very comprehensive and detailed (more complex what you need but maybe they will give you some inspiration) I am sure you will find what you are looking for:

> [@Time Series Forecasting with differenced series](https://forum.knime.com/t/time-series-forecasting-with-differenced-series/42152):
>
> Hello, how can I get the original values back from a forecasted differenced time series? The picture below shows my original series (Original GDP), the lagged column and finally the differenced column. I used the differenced column to forecast 2001 - 2003. The results from the forecast are shown in column E. To get the original values I used the last available original value (2000Q4) plus the forecast. But afterwards I need the “Forecasted Original” previous value to calculate the next original…

> [@How to create a loop between to equations using one's input as the other's output](https://forum.knime.com/t/how-to-create-a-loop-between-to-equations-using-ones-input-as-the-others-output/39741):
>
> Hello, I am working with a system of two equations where one’s input will be used as the other’s output. The first equation calculates the quantities to order for a month (n), and the second one the stock projection for the next month (n+1). This later will be injected as an input to calculate the ordering quantities for the month n+1 which in turn will be injected into the second equation once again to calculate the stock projections for n+2 which again will be input to calculate the stock proj…

Kind regards!

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [October 27, 2022, 9:21am UTC](https://forum.knime.com/t/how-to-use-recursive-and-chunk-loop-in-the-same-time/45518/7 "2022-10-27T09:21:12Z")

</div>

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