if with multi condition

hi every one .
i have a table with 5 column and 100row .
i wanna set a condition for each cell that check this condition =>
if length of that cell = 1 then replace something with something else .
how i can do this .?
thanks for your help

Hello @alrz,

you can use Unpivoting to get everything in one column, apply your logic and follow it with Pivoting node. See here how to do it:

For if/else logic in Column Expressions node check here:



hi @alrz , I’m assuming these are string columns. You may also be able to use String Manipulation (Multi Column) :

select only the columns that you want to act on, and use the following expression to replace “x” with “y”:

	1 == length($$CURRENTCOLUMN$$)

see the “conditional expressions” paragraph here for further info:

Mind you, given the cell length to check for is 1, I think that replacing “x” with “y” could be done as a simple literal replacement, using regexReplace:


hi @ipazin
thanks for your help bro . its work .

but please look at my pic

i write this and when run node the result be this

Why was this the result?
can you tell me where is the problem?

1 Like

hi @takbb
thanks bro . it was really my answer

do you found where is my mistake?

Hi @alrz, to match the above logic, using String Manipulation (Multi column) would be:

1== length($$CURRENTCOLUMN$$)
 :2== length($$CURRENTCOLUMN$$)

re the use of Column Expressions question to @ipazin, I think if you could supply the sample of data and the column expression that you have in your picture, it would be easier to assist.

The Column Expression you have shown doesn’t currently appear to match the result you have shown (e.g. in the output, the column is called “result”, and in the CE screenshot it is called “new”), and I don’t see how that Column Expression would have derived what you have in “result” from the displayed input data. Can you double-check this is actually the output produced.

yes i rename new to result to after send pic . otherwise new is same result .
yes your code is true and work . but i wanna found why that condition i write not true .
in below send true pic

main column :point_up_2:

code that i write in column expreession :point_up_2:


result :point_up_2:

Hi @alrz, Can you actually upload a small sample workflow containing that data and the column expression.

Unfortunately a screenshot is no good, since from the screenshot I can see no way that that column expression could append “00” onto the front of any data item, so if it is really doing that then there is something very subtle that I cannot see from looking at that picture, or else there is something weird going on.

yes bro . the sample data =>
and the column expression code = > “if (length(column(“ورود”) == 1)) {
join(“0”, column(“ورود”), “:00”)
} else if (length(column(“ورود”)) == 2) {
join(column(“ورود”), “:00”)
} else {
and then result => “009:47:00

the type of each column is string

It doesn’t though… that’s why I asked if you could upload a workflow that demonstrates it.

That column expression produces this:

What version of KNIME are you using?

Oh hang on… there is something odd… I’ll be back!! :wink:

OK… I’m back… :wink:

There is a subtle mistake in your code.

My code:

if (length(column("ورود")) == 1) {
    join("0", column("ورود"), ":00")
} else if (length(column("ورود")) == 2) {
    join(column("ورود"), ":00")
} else {

Your code

if (length(column("ورود") == 1)) {
join("0", column("ورود"), ":00")
} else if (length(column("ورود")) == 2) {
join(column("ورود"), ":00")
} else {

Look at the placement of the closing brackets in the first line
So replace your code with my code, and it should work

1 Like

version 5.2.3
sorry i cant upload workflow .

Please see the edit at end of my above comment.

oh oh very bad mistake .
really thanks bro for your help . :+1: :pray: