# Filtering answers of a single-select categorical question based on multiple external numeric variables

Hello all !
I have a filtering problem. I have three numeric variables, say VAR1, Var2, VAR3.
Then I have a categorical question with three options. I’d like each option to show up only if an associated variable is >= 1.
Thus, I tried as a filter to my categorical question:

VAR1 >= 1 ? @optioncode == 1 :
VAR2 >= 1 ? @optioncode == 2 :
VAR3 >= 1 ? @optioncode == 3 :
true

With the aim to show @optioncode 1 only if VAR1 >= 1 , etc.
I can’t find any examples of that in the public examples.
Many thanks for your help guys

Cheers
Noé B

Hello Noe,

Best, Sergiy

Hello @sergiy ,

Even reading the guidelines, I don’t see how to make this more clear. I’m just looking for a general syntax for filtering using multiple conditions

Maybe the problem is too simple, I don’t know.
Thanks anyway!
Noé

Hello all,

I came back on my problem with a second look, and I just did not try to encapsulate my different conditions into parenthesis. That was the key. Basically, if you have different conditional expressions (eg. VAR1 >= 1 ? @optioncode == 1 : true) separated by logical operators (eg. && or ||), they should be each between parenthesis. I thought that the console would read each expression separately by default, but it doesn’t.

Anyway, the solution here is :
**(VAR1 < 1 ? @optioncode != 1 : true) **
&&
(VAR2 < 1 ? @optioncode != 2 : true)
&&
(VAR3 < 1 ? @optioncode != 3 : true)

Hope that helps !
Noé

The operator precedence and order of evaluation is described comprehensively here:

No, there is only one filtering expression. It may be quite complex and handle numerous cases, but in the end it should evaluate to logical `true` (and then the corresponding option will be shown) or logical `false` (and then the corresponding option will not be shown). If an exception occurs during the evaluation of the filtering expression the behavior will be the same as for the `false` result.

Best, Sergiy

1 Like