# If statement with Error when some variable of the statement doesn't exist

Hi,

I am trying to figure out which node to use to make a FLAG where the condition is IRR>=30 → FLAG=1.
my workflow is looping on the “plant” and every plant has its own number of IRR_ columns.
In my table, I can have 4 possibilities of having inside :

1. one column called IRR_1
2. 3 columns with IRR_1, IRR_2, IRR_3
3. 6 columns with IRR_1,IRR_2,IRR_3,IRR_4,IRR_5,IRR_6
4. 9 columns with IRR_1,IRR_2,IRR_3,IRR_4,IRR_5,IRR_6,IRR_7,IRR_8,IRR_9

but obviously, I don’t know when I will have which one it depends on the “plant”.

So the first point is to find the number of IRR_ columns and I have it, working with Extract header and Value Counter so at the end I have a column named count where I have a number of IRR columns in the table.

So I wanted to use the Column Expressions to make an IF statement and make this condition:

if(column(“count”)==1 & column(“IRR_1”)<= 30){
0
}
else if(column(“count”)==3 & column(“IRR_1”)<= 30
|| column(“IRR_2”)<= 30
|| column(“IRR_3”)<= 30) {
0
}
else if(column(“count”)==6 & column(“IRR_1”)<= 30
|| column(“IRR_2”)<= 30
|| column(“IRR_3”)<= 30
|| column(“IRR_4”)<= 30
|| column(“IRR_5”)<= 30
|| column(“IRR_6”)<= 30){
0
}
else if(column(“count”)==9 & column(“IRR_1”)<= 30
|| column(“IRR_2”)<= 30
|| column(“IRR_3”)<= 30
|| column(“IRR_4”)<= 30
|| column(“IRR_5”)<= 30
|| column(“IRR_6”)<= 30
|| column(“IRR_7”)<= 30
|| column(“IRR_8”)<= 30
|| column(“IRR_9”)<= 30){
0
}
else{
1
}

To get the FLAG which depends on number of the columns and also the value of IRR inside the table.

The error that occurs to me is:

"ERROR Column Expressions 4:9:2612:77:75 Execute failed: An error occurred in script 1:
Column ‘IRR_2’ is unknown."

In the loop where I am working, in my actual table, I have only one IRR_1 column so the if condition should stop on the first statement but it is not stopping and it proceeds to the second condition, I think, and this produces the error. How can I make it work? does Column Expressions consider also some “pass” statement if the condition doesn’t exist or it’s not satisfied?

Hello @pnotova ,

I think I have understood your problem and the error shown.
According to what you’re trying to do, you could split the workflow according to the count column (using some row splitter nodes or a more elegant case switch node). Once the main flow has been splitted, you can configure a column expressions node (or a rule engine, in you prefer) with the rules specific for the count number.

Hope it helps.

Have a nice day,
Raffaello Barri

4 Likes

Hi @pnotova

You could try using the -Unpivoting- node inside your loop with a wildcard or RegEx to always unpivot the IRR columns no matter how many appear:

This means that the IRR data will end up in one column (I’ve used dummy data here):

Then use the Rule Engine to assign the Flag column based on your rule IRR>=30

Hope that helps
Heather

4 Likes

Thanks to both it is really interesting see how the minds are working

I have used the first solution it is more suitable for may case!

thanks and have a nice day

Petra

2 Likes

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