# Dynamic row calculation of columns

Hi,

I need to make the following calculation in Knime:

I tried with Moving Aggregation and Lag Column, but the thing is that I cannot do the multiplication within the moving aggregation. Can anyone help with this? Thanks.

Can you upload a workflow with some sample data in it? It is also hard to tell what columns you are referencing in your formulas. What are the column names for âFâ and âGâ? Is row 2 in the formula the 1st row with data (aka Number = 6)?

Not sure how to edit the post, but here is the screenshot with the columns:

Super confusing to my eyeâŚ All of the cells referenced in the formula appear to be blank.

It will be much easier to see this in KNIME. You can get an upload friendly workflow file by going to File â Export KNIME WorkflowâŚ Then make sure that Reset workflow is not checked when you save it.

Iâm not really sure what you meanâŚ The first table is how the data looks now, and the second table is what the outcome should be. The column âformulaâ just shows which formulas have been used for each row in column G.

But I have attached the workflow with the data now.

data.knwf (6.7 KB)

1 Like

Hello @aj05 and welcome to the KNIME forum.
This is your workflow:

1. Send your column \$F\$ to variable \$\${DF}\$\$
It takes the first row by default

2. Rule Engine column \$factor\$:

``````NOT \$F\$ = \$\${DF}\$\$ => \$F\$
TRUE => 1
``````
1. Moving Aggregation \$Product\$
You can control the window length as variable from a âTable Dimensionâ node (not included)

2. Math Formula:

``````\$\${DF}\$\$ * \$Product(factor)\$
``````

BR

4 Likes

First thought of a lag column node but I like @gonhaddock great solution. MA Node for the win.

3 Likes

I had started a lag column solution when this one popped up. Very cool approach. I am going to start looking for opportunities to use the Moving Aggregation node more often.

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