# How to set lag no.as variable to run loop in Lag column

**URL:** <https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111>\
**Category:** KNIME Analytics Platform\
**Created:** [July 15, 2022, 9:33am UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111 "2022-07-15T09:33:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chenfang](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@Chenfang](https://forum.knime.com/u/Chenfang)\
**Post date:** [July 15, 2022, 9:33am UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/1 "2022-07-15T09:33:32Z")

</div>

Hi Knime experts  
I have below part with difference lag request for demand.  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/e/ce134ab17f2e8238d5362c803f6d5364eb105be5.png)  
I use table row to variable loop start to set lag no. as variable, but I don’t know what’s wrong, the workflow can get the result what I want.  
Thanks for help in advance.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/5/351a00d599cd86c1a5e2a9a4c79a89928bb09ffe.png)

Below picture show my workflow result and what I want, hope it’s clear for understanding.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/0/10bd901e669a7d24526ca29fb0c4dbcbd8d001db.png)

---

<div class="post-metadata">

**Author:** ![lelloba](https://forum-cdn.knime.com/user_avatar/forum.knime.com/lelloba/32/43992_2.png) [@lelloba](https://forum.knime.com/u/lelloba)\
**Post date:** [July 15, 2022, 10:08am UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/2 "2022-07-15T10:08:21Z")

</div>

Hi @Chenfang,

is something like this working for you?

> **[Lagging with parameter – lelloba](https://hub.knime.com/lelloba/spaces/Forum/latest/Lagging%20with%20parameter~ScLFtQfMwYNcM3gu)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

Let me know,  
RB

---

<div class="post-metadata">

**Author:** ![Chenfang](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@Chenfang](https://forum.knime.com/u/Chenfang)\
**Post date:** [July 15, 2022, 10:30am UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/3 "2022-07-15T10:30:28Z")

</div>

Hi Lelloba  
Thank you so much for your prompt reply and perfect solution. It works.

---

<div class="post-metadata">

**Author:** ![Chenfang](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@Chenfang](https://forum.knime.com/u/Chenfang)\
**Post date:** [July 15, 2022, 12:19pm UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/4 "2022-07-15T12:19:32Z")

</div>

Hi Lelloba  
I have another question, if I want lag with negative, how to set up, thanks!  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/7/f7cce595a5bd0447aa8b90b3c9f80008fc0f4831.png)

---

<div class="post-metadata">

**Author:** ![lelloba](https://forum-cdn.knime.com/user_avatar/forum.knime.com/lelloba/32/43992_2.png) [@lelloba](https://forum.knime.com/u/lelloba)\
**Post date:** [July 15, 2022, 12:24pm UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/5 "2022-07-15T12:24:26Z")

</div>

In that case you have to use another node called Moving Aggregation.

 ![immagine](https://forum-cdn.knime.com/uploads/default/original/3X/0/2/026ad07c6e0839c9d3d95e6f5e91510d22a08f0f.png)

See this post: [Lag Column with Negative value? - #8 by Isabell](https://forum.knime.com/t/lag-column-with-negative-value/7622/8)

Alternative: this node

> **[Lead – riznylafi](https://hub.knime.com/riznylafi/spaces/Public/latest/Lead~SyLKXhpdktvd2z8R)**
>
> Lead for a column. This node will return Lead columns which is similar to Negative Lag Columns

RB

---

<div class="post-metadata">

**Author:** ![Chenfang](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@Chenfang](https://forum.knime.com/u/Chenfang)\
**Post date:** [July 15, 2022, 12:28pm UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/6 "2022-07-15T12:28:34Z")

</div>

OK, thanks, let me try.

---

<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:** [July 22, 2022, 12:29pm UTC](https://forum.knime.com/t/how-to-set-lag-no-as-variable-to-run-loop-in-lag-column/45111/7 "2022-07-22T12:29:17Z")

</div>

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