If Else logic in column expressions

I am trying to write a if else logic
howerver the logic seems to fail. The and condition statements don’t seem to work for me. I am referring to all string fields. Do we have a simple if else way to do things since this is frustrating.

my logic is
if
(column(“a”) == “abc” && column(“b”) in (“def”,“ghi”)
{
“a”
}
else
{
column(“a”)
}

The logic doesn’t throw an error but it gives a ? in the result. I don’t know how i can troubleshoot it.

Hi @r_jain

For such a string comparison, you need to use .equals("").

So
(column(“a”).equals("abc")

If this does not work out then please share a sample of your dataset or the workflow.

For in (“abc”,“def”) equals doesn’t seem to work. What can i use for it?

I saw you changed that just after my reply :wink: I would change to the Rule Engine for the IN statement.

:frowning:
This is a bit frustrating but nevertheless thank you :slight_smile:

How about the below? In a brief bit of testing this worked for me:

if (column("a").equals("abc") && contains(column("b"),"abc","w") || contains(column("b"),"def","w")) 
{"a"}
else
{column("a")}
1 Like

Thanks Scott for your response.
Unfortunately, i have 50 odd strings that are supposed to be equated with. The easiest i could think was using the IN operator.
The solution which you mentioned, while it works but its really cumbersome to write as the number of strings to be matched with increases in number.
I hope the newer versions of KNIME do tackle this and make it easier for the rest.

Try to use Rule Engine Dictionary. This way you can add or remove necessary words dynamically.

2 Likes