Loop through a table and re-using calculated values

I’ve started using knime pretty recently and I came across a situation which I’m not sure how to solve. I have a table with a constant value column as shown in the image (or I can use a second table with one row with this constant value). What I need to do is to subtract the first row of Column 2 from the first row of Column 1 (65-90=-25) and then use this result to subtract the value of the next row on Column 2 from it (-25-23=-68) and so on.

In order words, what I want to do is to update the initial constant value (65) with the results of the previous calculation, so the resulting table would be like:

| Column1 || Column2 |
| 65 || 90 |
| -25 || 23 |
| -48 || 62 |
| -110 || 16 |

I appreciate your help! Thank you!

Table

Hi @monge88 and welcome to the Knime Community.

You can do this using the Moving Aggregator node:

The trick is to make that Column 2 to start with 65:
| Column2 |
| 65 |
| 90 |
| 23 |
| 62 |
| 16 |

Note: What happened to the other values from the screenshot? It would have helped if you provided all the rows that you had in the screenshot.

So I put something together using the 4 values I could copy and paste.

Input:
image

Results:
image

Workflow looks like this:

Here’s the workflow: Loop through a table and re-use calculated values.knwf (26.0 KB)

3 Likes