Is there a way to make a If Then on Knime

I recently have been working on MANY jobs that require me to check a column for a code in a document and this code has some sort of value attached to it in another column, then on another document i have the same set up but with a different value, i need to make the changes on every code that matches while leaving the value in the ones that dont match
image
here a small example of the idea where in the first document the code 1 and 3 dont match with the second document so i change the value in the second document

(btw it dont need to be the 2 documents if it is possible to just grab the value column, add in the document 2 on and then work with the values in the same document that also would already help enough)

so TL;DR if document 1 code matches document 2 then value of document 2 becomes value of Document 1
(or also a possibility)
Joiner both documents and then do this process on the same document so i can have a column with the correct values

Hello @Bleck,

in your case Cell Replacer node should do it.

For anyone interested to know more on how to do If Else statements in KNIME there are already many discussion so give forum search a try. For example here is one topic:

Br,
Ivan

4 Likes

it kinda work but the problem is on the cell replacer (as far as i know) you would look at the code of document 1 compare with code in document 2 and on document 2 exchange the code with the value of document one, i need the value to be exchanged in the column value in the document 2 with document one, reading your documents maybe column expression would work
something like
Joiner both documents to have both in the same document and the same line, then in column expression

if (column(“Code1”) == “column(“Code2”)”);
(column(“Value1”) = “column(“Value2”)”);
else
(column(“Value2”) = “column(“Value2”)”);

hope this explains better what i want

Have you used column expressions node?
br

2 Likes

Hi @Bleck ,

Some cases, i used the rule engine and define a variable to set all cases, even the cases that don’t need attention. For each case, I set integer number to identify it… start from “0” to “x” cases.

switchcase.knwf (22.6 KB)

I made it to use as port matches at switch/case nodes… the ports start with “0” and you can add many ports for each case… Just put after the rule engine a table row to variable node and connect just this port at the switch node as flow variable.

image

Here you set the rules/conditions as “IF else sentences”. And save the result as “port” column.

Put the port as flow variable.

I remove the port column from the data path, I don’t need it for going on after.

I bring the flow variable to validate the row and go throw the port value (0,1,2,3…) that i set at rule engine node.

And that’s it… From the switch, for tests, mark the option to see all ports, but for real state, uncheck it for security process, ok?

I understand that it can solve your problem… maybe a quick solution, but you can try others solutions too…

I hope that helped you.

Seeya,

Denis

2 Likes

i had to look in to it but i made it work i joiner all in the same document and then i did in the column expression
if (column(“Code1”) == column(“Code2”))
{column(“Value 1”)}
else
{column(“Value 2”)};
was having a LOT or problems with the actual code but hey now it works so good enougth XD

1 Like

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