Calculation with IF-statement in Java Snippet

Dear KNIME community,
I need a very short help in JavaSnippet.

My requirement is to do a calculation in JavaSnippet based on IF-condition AND to create new column AND fill it out with these calculations.

For example, below is a table with 4 columns, and since a table view is not possible, I show it by row values:
(salary): 1000,1500,3000,5000
(employee): Anna, Peter, Max, Gregor
(bonus): 500,500,500,500
(overtime): 700,700,700,700

ā€“> Java Snippet should do the following:

IF [Salary > 1500] => [Salary]+[bonus] => create and fill out the new column.
IF [Salary <= 1500] => [Salary]+[overtime] => fill out the new column further.

The result should look like this:
(salary): 1000,1500,3000,5000
(employee): Anna, Peter, Max, Gregor
(bonus): 500,500,500,500
(overtime): 700,700,700,700
(newcol): 1700, 2200, 3500,5500.

THANK YOU very much in advance,
:slight_smile:

Hi,
you can even use a Java Snippet (simple) node for it. You can use the following code:

if ($$salary$$ > 1500) return $$salary$$ + $$bonus$$;
else return $$salary$$ + $$overtime$$;

You have to fill in the correct placeholders for your columns. Then in the configuration at the bottom, select to create a new column of the chosen name and select Integer as data type.
Kind regards,
Alexander

4 Likes

Thank you! Worked perfectly!
Kind regards,

2 Likes

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