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.

3 Likes

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,

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

Hope this helps.

Br,
Ivan

5 Likes

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!

~ Haystack

2 Likes

Hi @Haystack,