If Else in Column Expression

This workflow demonstrates how to do different If/Else constructions in Column Expressions node.


This is a companion discussion topic for the original entry at https://kni.me/w/srzVYM5I6NUM53eR
2 Likes

This tripped me up and I was pulling out my hair for a while…

Note the == is used for evaluation of nominal values. I should have remembered but it been a long time.

1 Like

Thanks for providing the column expressions examples!
Very helpful, indeed.

It would be very helpful though, if there would be a low code solution for the everyday business user, that would allow powerful if else statements with a possibility to do data operations afterwards (Math formula, string manipulation etc.)

1 Like

Hello @Residentstiefel,

glad to hear that. Yep, I do totally agree with you. Will forward it and let’s see.

Br,
Ivan

1 Like

This is awesome. I am trying to normalize a date field where dates appear in one of these two formats. The dates are stored as Strings since they are different.
2021-04-08 or 04/21/2021

I would like to write a formula that will make the dates like the first format i.e yyyy-mm-dd. I am trying the below but something is wrong with my syntax. Any help would be much appreciated.

if (regexMatcher(column(“BEGIN_READ_DATE”),"/" ) = True)
{
substr(column(“BEGIN_READ_DATE”),7 ,4 ) & ‘-’ & substr(column(“BEGIN_READ_DATE”),1 ,2 ) & “-” & substr(column(“BEGIN_READ_DATE”),3 ,2 )
}
else{
column(“BEGIN_READ_DATE”)
}

1 Like

Hi @Shmelky , you should expand on what do you mean by “something is wrong with my syntax”.

Are you getting any syntax errors? If so, what are they?

A few comments:

  1. A single equal = is an assignment, while a double equal == is a comparison. Because you are doing “= TRUE” instead of “== TRUE”. that if statement will always be true.
  2. I believe you would want to concatenate these substr, and the way to do this is via the join() command, such as:
    join(substr(column(“BEGIN_READ_DATE”),7 ,4 ), "-", substr(column(“BEGIN_READ_DATE”),1 ,2 ), "-”, substr(column(“BEGIN_READ_DATE”),3 ,2 ))
    Using the & sign means “and” (vs “or”), usually used to define a condition. For example:
    if (value > 0 && value < 10) {do something}

BTW, is there any reason for the inconsistency about single quotes and double quotes? You are using both single quotes and double quotes in your statement (& ‘-’ & and & “-” &)?

2 Likes

Thanks! Worked. Single versus double quotes was a mistake. No reason for it

1 Like