IF-ELSE SYNTAX IN COLUMN EXPRESSIONS

Hi.

I need to create an If-Else condition in the node Column Expressions as follow:

If column A = column B
then column B
else “”
end

I don’t know the syntax in knime.

Tks.

Daniel Kataoka.

Hi @danielkataoka

In this topic a question was added on a similar issue. In one of the replies I added an example workflow in which you can find how to do this.

Next to this Column Expression node you could use a Rule Engine node to achieve a similar condition.
In there you would have to use coding like this:

$columnA$ = $columnB$ => $columnB$
TRUE => ""

which would give the same result as required by you.
Rule Engine’s follow the logic that the first condition which is met will be used and the rest will be ignored.

1 Like

Hi @JanDuo

Thanks for your answer.

In my case I have on more problem, three columns to use with the same condition.
For example,
$columnA$ = $columnB$ => $columnB$
TRUE => “”
$columnA$ = $columnB$ => $columnC$
TRUE => “”
$columnA$ = $columnB$ => $columnD$
TRUE => “”

If I use Rule Engine I will only replace one column at a time, right?
So I will need to add three nodes, Isn’t there a way to use just one?

@danielkataoka, Look at discussion here

1 Like

@danielkataoka, indeed with a Rule Engine node you can only add/change one column at the time.

As indicated by @izaychik63 there has been a similar discussion on this topic earlier. You have to decide yourself what you find most important.

Is one node in your workflow the most important? You can change the three Rule Engines into a Component or Metanode to. When you do this you can change the jobmanager into Simple Streaming in the configuration of the Metanode or Component, which will improve performance too (performance was discussed in this other topic too).
afbeelding

Just try the different options and see what works best for you.

Hello @danielkataoka,

If you want to use only one node Column Expressions would be the one. See here for intro to it: https://www.youtube.com/watch?v=_3EJ5cYdhwI&ab_channel=KNIMETV

In case columns are numerical you can use Math Formula (Multi Column) node with if() function to achieve same.

Hope this helps!

Br,
Ivan