IF STATEMENT - REPLACING NULLS

Hi all, I’m new to KNIME, but I have worked with other ETL tools before.

The weird thing I experience issues with here is the IF statement, the most basic thing. Nowhere can i find a proper example how to do it, only very specific example that did not work for me.

My current example looks like this:
IF $Genre$ is null THEN $Subgenre$
ELSEIF $Genre$ is null AND $Subgenre$ is null THEN “Unknown”
ELSE “Unknown”

Basically replacing nulls in a column with values from another one.

Can someone please help?

Hi filipisai,

welcome to KNIME and the forums.

I would approach this by using a Rule Engine Node and the MISSING function within that (see screenshot).

What the expression says is basically this …

  • if the Genre column AND the Subgenre column have a missing value, then write unknown
  • if only the Genre column has a missing value, take the value from the Subgenre column
  • for everything else just keep the Genre column

I have attached the workflow to the hub, see below

Let me know, if that helps.

2 Likes

Hi Kowisoft, thank you, this worked! Guess I need to dig deeper for some things :slight_smile:

1 Like

Glad that it worked :slight_smile:

This forum is one of the best I have ever seen in support and community. Every question / problem I had has been solved here :wink: (Marketing off :smiley:)

2 Likes

OMG!!! so TRUE => is basically ELSE to the previous statements?

1 Like

@Gavin_Attard yes, I think so. TRUE is the default outcome, which I would interpret as being the equivalent to ELSE in programming languages (but hey, I’m not a developer by any means :wink: )

1 Like

Hello!

@filipisai for dealing with missing values there are also Missing Value and Column Merger nodes. For more complex if/else constructions you can check Column Expressions node. Welcome to Community!

@Gavin_Attard yep or as noted in commented rule inside node “default outcome” :smiley:

Br,
Ivan

2 Likes

lol, The amount of times i struggled to get the else condition done… woop woop

2 Likes

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