Calculating an Equation in KNIME


I have a data set which looks like this 

id    prob

1      0.55     ----> (p1)

2      0.36     ----> (p2)

3     0.045   -----> (p3)

4     0.023   -----> (p4)


I need to calculate the below equation:

 var  =  1 - p1 - p2- p3 - p4

Looks easy but I'm not able to figure out a simple workflow to do it. Please let me know how could I solve this ?

Thanks !



Mohammed Ayub

Hi Mohammed,

the Math Formula node has a COL_SUM() function which can sum all elements in a column.

In your case the formula:

1 - COL_SUM($prob$)

will give the expected result. Note that you will get 4 times the same result, one for each row of the original table.

As an alternative method, you can use the GroupBy node and just manually aggregate on the prob column with method "Sum". Then add the Math Formula node to subtract the result from 1. WIth this method you end up with only one row with the result as last column.

If you need to assign the result to a Flow Variable, you can use the Row Filter node to retain only the first row (necessary method 1 only) and then Table Row to Variable node to turn your result column into a variable.


Thanks Marco ! I got it working using a simpler method:  "Group By" node on Prob and then using "Math Formula" to calcualte the final equation. 



Mohammed Ayub