Calculator with if/else statement

My problem right now is, that i would like to have a calculator function which first checks if a specific scalar (CONC_001) is greater than 0.1. If that is the case it should simply calculate: CONC_003 = CONC_001 / CONC_002. Is CONC_001 smaller than 0.1 CONC_003 should be set to 1000.

Is there a filter to do this check in order to create new cell data with either 0 or 1. So then i could use the simple calculator filter for the final calculations.

Thanks a lot :slight_smile:

you should be able to do that with the Python Calculator, and a one liner like result if cond else othervalue

1 Like

Thank you, i already tried it like this:
value_when_true if condition else value_when_false
But somehow it only takes the values of “value_when_true”. It doesn’t check the if condition.

Is it important that it is a Multi-Block DataSet? Because when i do “MergeBlocks” and then use the PythonCalculator with “np.where(condition, value_when_true, value_when_false)” it works fine. But i want to avoid merging the blocks.

I agree with Nicolas that Python Calculators should be preferred, but I will note that in a pinch the old style calculator does support ternary style if expressions.
Test with Wavelet and this Calculator expression:
“if(coordsX>1,1,0)”

1 Like

Wow i didn’t know the normal calculator is able doing this. This works fine for me :smiley: thank you very much. But can you explain why the same code doesn’t work in the PythonCalculator?

The original calculator works with if statements because now it has the exprtk library as backend. I can’t answer about the Python calculator.