# if then else with multiple conditions

**URL:** <https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150>\
**Category:** KNIME Analytics Platform\
**Created:** [September 17, 2021, 9:03am UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150 "2021-09-17T09:03:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgknime](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sgknime](https://forum.knime.com/u/sgknime)\
**Post date:** [September 17, 2021, 9:03am UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150/1 "2021-09-17T09:03:17Z")

</div>

Hi there

I am new to knime and try to migrate workflows from SPSS Modeler to KNIME. I stuck on applying a derived field:  
How can I derive (create) a new variable by using if then else with multiple conditions on existing columns? Which nodes are best for the following example?

if (var1 \> 0 and var2 \> 0) or (var3 + var4 \> 0) then 1 else 0 endif

I tried different nodes (column expression, rule engine, math formula) but wasn’t able to make it work.

Thanks for help or a hint.

Best regards, Sinan

---

<div class="post-metadata">

**Author:** ![Experimenter](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/5daacb/32.png) [@Experimenter](https://forum.knime.com/u/Experimenter)\
**Post date:** [September 17, 2021, 9:54am UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150/2 "2021-09-17T09:54:28Z")

</div>

For simple comparison rules you can use Rule Engine node. It will not allow you to sum up something, however - so you need to do your calculations prior to rule engine using Math node.

---

<div class="post-metadata">

**Author:** ![izaychik63](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/i/e9a140/32.png) [@izaychik63](https://forum.knime.com/u/izaychik63)\
**Post date:** [September 17, 2021, 12:03pm UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150/3 "2021-09-17T12:03:04Z")

</div>

See syntax examples here [JavaScript AND OR in IF Statement to Check For Multiple Conditions](https://a1websitepro.com/javascript-and-or-in-if-statement-to-check-for-multiple-conditions/)  
Use [Variable Expressions — NodePit](https://nodepit.com/node/org.knime.expressions.base.node.variableexpression.VariableExpressionsNodeFactory)  
for variables or  
[Column Expressions — NodePit](https://nodepit.com/node/org.knime.expressions.base.node.formulas.FormulasNodeFactory)  
for table cells.

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [September 17, 2021, 12:08pm UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150/4 "2021-09-17T12:08:44Z")

</div>

Hello @sgknime,

and welcome to KNIME Community!

For [Rule Engine](https://kni.me/n/zpGPAjDyExkFL2HB) if else logic see here:

> [@If else in rule engine](https://forum.knime.com/t/if-else-in-rule-engine/15334):
>
> How to apply if else in rule engine?

For [Column Expressions](https://kni.me/n/2_0ji_xeG-SudFu-) if else logic see here:

> [@COLUMN EXPRESSION: IF ... else](https://forum.knime.com/t/column-expression-if-else/28188):
>
> Hello…I am new to KNIME, not new to IT. Can you please help with syntax on this pseudocode IF col1 = ‘ABC’, then col2 \* 10 else min(col4, col5)\*col2 \* 10/2 end I am completely confused with various {[(, to be manipulated there… Thanks!

For [Math Formula](https://kni.me/n/2fI5rIsFDCFPHc0R) if else logic see here:

> [@IF STATEMENT](https://forum.knime.com/t/if-statement/25476/2):
>
> Hi there @SimoneDePaoli, in this case I would use [Math Formula](https://kni.me/n/2fI5rIsFDCFPHc0R) node and if() function cause you have numeric columns. This would be syntax: if(a \> b, c \* b, b) In case you are looking for some more complex if/else statements or string columns are included see this topic about [Column Expressions](https://kni.me/n/2_0ji_xeG-SudFu-) node: Br, Ivan

In your case I would go with Rule Engine 😉

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![sgknime](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sgknime](https://forum.knime.com/u/sgknime)\
**Post date:** [September 20, 2021, 11:00am UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150/5 "2021-09-20T11:00:44Z")

</div>

Thank you very much to all of you for your answers and hints and links. After that I think it’s best to go with the rule engine. I can rewrite my logic though I was interested how such a simple comparison could be done 1:1 in KNIME.

Thanks again!  
BR, Sinan

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [March 21, 2022, 11:01pm UTC](https://forum.knime.com/t/if-then-else-with-multiple-conditions/36150/6 "2022-03-21T23:01:06Z")

</div>

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