Create a new Column using 50% of the row before plus the actual row

Hi Knimers!

I'm trying to create a new column using another column as reference.

The task is to create a kind of "moving average" using 50% of the row before my actual row plus my actual row but not considering this math for the first row of data.

Here is a simple example:

Column A     New Column            Explanation of the task

10                        10                         (Dont consider the math)

20                         25                        (50% of 10 +20)

50                         63                         (50% of 25 +50)

15                         46                          (50% of 63 +46)

Any help?


Hi Fabio,

pretty easy to do with a Jana Snippet (simple) node using a global variable to keep track of the previous result.

See the attached workflow.


Hi Marco!
Thank you! Indeed, very easy!

The point is that I don't know Java and I'm always avoiding coding.

Can you recommend me a fast way to learn Java only to use the Java Snippet? It seems that is more effective.

Thank you again!


Hi Fabio,

gald it helped you. Actually there is a way to achieve the same result without using a Java Snippet node, but it is very complicated and uses Recursive Loops + Flow Variables. I can post it for you if you would like to take a look.

The solution using a Java Snippet code is more compact and easier to maintain. To use a Java Snippet code for applications similar to yours you don't need to become a fully fledged Java Programmer, it is enough to know the basic Java math.

Here is a tutorial you can look at:

There are many others available on internet. Just google "Java math" or similar.