# 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

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 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.