Need Help with a Simple IF THEN Statement

I am trying to do a simple if-then calculation such as:

IF [Column A] = 4 THEN [Column B] * -1
ELSE [Column A]

I want to take a price column and make it negative for returns. I have looked at the Rule Engine, Column Expressions, Java Snippet, Column Lag, and other nodes, but it is still not clear how to make this simple calculation. Can some please offer any suggestions? Thank you.

For Column Expression this will work
if (Column(β€œA”) == 4) {Column(β€œB”)* -1} {Column(β€œA”)}
in case your columns has name A and B.


Hi @izaychik63,

Thank you, that worked! Can you tell me of any resources to learn more about the Column Expressions node? I can’t find many examples of the syntax used. Thank you.

Hi there @Haystack,

there is plenty material to learn more about Column Expressions node. First to mention that node uses JavaScript language so you can check this page to learn more about syntax you need.

Also this video by KNIME gives you node introduction and this blog post by @armingrudd presents a use case with example code with screen shots :wink:

Hope this helps.



Hi @ipazin,

Thank you for sharing these resources! After reading @armingrudd’s blog post, I can see how powerful the Column Expressions node is! Now, I need to learn a little javascript! :smile:

~ Haystack


Hi @Haystack,

glad to hear that :slight_smile:


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