Error in Column Expression

Hello,

I want to copy one cell value to a other cell, if a condition is matched.

if (column(“car_id”)==0){column(“car_id (right)”)}{column(“car_id”)}

if car_id = 0 then copy the vaule of car_id (right) into car_id

Can someone help me out?

thanks and all he best,
sven

Hi @sven-abx , assuming you really want to use column expressions for this, you could do it as follows:

if (column("car_id")==0 )
{column("car_id (right)") }
else
{
column("car_id")
}

which I guess is pretty much what you were doing, but had just missed out the “else” keyword.

I think other than that what you were trying to do was correct (e.g. you would have to tell it what to place in “car_id” if the condition is not met to prevent it being set to missing.)

A simpler alternative though is rule engine:
image

Or another option (just for giggles!) is a combination of rule engine (to turn zero into “missing”) and then performing a column merge, which appears to be what you are doing:
image

image

Conditional Copy Column Value.knwf (11.9 KB)

4 Likes

Hi @takbb,

thanks for your reply. I want to use Column Expression, because I need to do this with several fields and wanted to handle this in one Node.

Thanks and all the best,
Sven

2 Likes

Hi @sven-abx , indeed in this case, the Column Expression would be better instead of having multiple Rule Engine nodes.

2 Likes

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