Knime - If Switch (Conditions)

Hi! Is it possible to set-up a condition where it allows switches to flow on both sides? Thanks!

Hi @JohnAndehl and welcome to the forum.

The “both” option in the dialog will allow for both output ports to remain open. Is this what you need?


What I’m actually trying to do is to set-up a rule where if it satisfies this one condition, it would only open one port. Otherwise, the both output ports would remain open.


Hi @JohnAndehl

I believe that Scott is hinting at the If-Switch rather than the CASE switch since the If-Switch has the option to go top,bottom or both:


Maybe below setup can give you some inspiration:

Let’s assume the following data:


By applying a rule engine, I determine whether each row should go in the switch:


If you only want to go top or both, then use

$PARAM1$ = "AA" => "top" 
TRUE => "both"

With the direction now established, I pass this ‘direction’ value as flow variable to an If-Switch (that will control the chosen Port Index.


For this example, I just apply a static value to verify if the row went top, bottom or both (via the Constant Value Column).

After the rows have been processed, it can be observed that “CC” was processed by top and bottom individually in accordance with it’s PortIndex being set to Both.


See WF:
if switch loop.knwf (44.9 KB)

Hopefully this helps in any way.


Hi @ArjenEX , this is very helpful. However, I’m trying to create a switch for paths. Is it possible to have path ports (instead of data ports) in the “If-Switch” Node ? Thank you!

Hi @JohnAndehl

Not to my knowledge. But you can circumnavigate this quite easy. I’m still not sure what your full use case is but assumingly you want to process files in a certain way that fulfill a particular condition based on the path.

Changes I made:

  • Get all files from a directory (random example).
  • Convert the Path to a string equivalent.
  • Apply a rule to the string path (for example: all rows that have a csv file extension should go top, the rest goes bottom).

The rest is similar as before. At the end, all csv’s went top and the rest (meta,sqlite,xls and table) went bottom. You still have the original Paths available as well.


Got it! Thank you for this.


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