Hi All,
I´m trying to introduce conditionals in a workflow, checking a condition a producing different output options, for example:
IF [COLUMN1] >= [ COLUMN2]
THEN [COLUMN3]
ELSE [COLUMN4-COLUMN5]]
ENDIF
I tried with Rule Engine, but I wasn´t able to introduce operators in the result (that is, if the condition is met, the result is an operation between two columns). It seems that only a specified outcome is expected
Hi @raulpresa , and welcome to the KNIME community. As you have found the Rule Engine is limited to returning literals or single column/variable values but cannot handle any form of calculation or manipulation.
Conditional value calculations can be included in KNIME by using the Column Expressions node, which you may need to install.
There is also now a Variable Expressions node which is the same but for flow variables.
There are other way of doing conditions too. The Math Formula node has an if statement but is limited to working with numeric values only.
Beyond that Java Snippet is also an option but does require some Java knowledge and arguably a slightly higher learning curve.
For the type of expression you have as an example I would suggest Column Expressions, but if you have to execute it on large amounts of data, String Manipulation or Java Snippet will be much faster.
Thank you @takbb I tried with Column Expressions and worked very well for my needs!!.
Do you know if there is documentation about building expressions in Knime or I just have to refer to Java documentation for that?
Thanks again,
Hi @raulpresa , I’m glad that helped and you’ve managed to get it working for your needs.
The column expressions node is based on JavaScript syntax so yes getting comfortable with JavaScript is the way forward. I haven’t found much written information apart from the documentation on the node itself, but I would suggest taking a look at the intro video for the expressions nodes here:
There are a couple of videos to be found on YouTube but it probably depends on your own background as to how useful they will be.
Searching the forum for discussions on column expressions will hopefully provide useful examples too, but if all else fails and you cannot find the answer you need then please post a question in the forum.