Survey123 - Using OR Statements in the Choice Filter

1020
7
11-26-2019 04:19 PM
DarrenSchouls
New Contributor II

Hi there,

I am currently putting a survey together using cascading selects and the choice filter. Everything works great until I tried to include an "OR" statement in a choice filter. The syntax I have been trying is below:

WetlandClass=${WetlandClass} and WetlandForm=${WetlandForm} and (WetlandAcidity=${WetlandAcidity} or WetlandPermanence=${WetlandPermanence})

Does the choice filter support OR statements? And if so could you provide an example of the syntax.

Thanks for your help,

Darren

Tags (2)
0 Kudos
7 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Darren,

OR is supported in a choice filter - see the sample attached.  You may need to check to make sure the combination of your statements make sense with the values selected.

0 Kudos
DarrenSchouls
New Contributor II

Hi James,

Is it possible that the filter struggles when there are several AND statements as well as an OR statement? Everything works fine when I have 3 AND statements but as soon as I try to add the OR statement near the end several options for questions do not appear. Again the syntax in my choice filter is below:

WetlandClass=${WetlandClass} and WetlandForm=${WetlandForm} and WetlandAcidity=${WetlandAcidity} or WetlandPermanence=${WetlandPermanence}

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Your statement is possibly ambiguous; normally with a mixture of AND and OR you need to use parentheses to make the order of operations clear. It would be helpful to see the combinations of choices and values to figure out if the logic is doing what you want.

0 Kudos
DarrenSchouls
New Contributor II

Hi James,

I have attached the XLS sheet for my survey. The issue is occurring on line 23 when the Salinity question is being asked. I added brackets into the statement within the Choice Filter but when I test the form the options that should appear for the "Wetland Salinity" field remain hidden. All of the choices are within the choices sheet, not the external choices sheet. 

Essentially what I need the form to do is:

- If "Bog" or "Fen" is chosen for the "Wetland Class" field then the "Wetland Acidity" field will appear. Based on the answers to the "Wetland Form" and "Wetland Acidity" the appropriate options for the "Salinity" field should appear.

- If "Marsh", "Shallow Open Water" or "Swamp" are chosen for the "Wetland Class" then the "Wetland Permanence" field will appear. Based on the answers to the "Wetland Form" and "Wetland Permanence" the options for the 'Salinity" field will appear.

So far everything works as it should except that the options for the Salinity field just never appear. As soon as I get rid of the OR statement and only have 3 dependencies in the Choice Filter the options will appear in the Salinity field but only if all three questions in the Choice Filter are answered. I realize it might be a pain to test all this but any help would be greatly appreciated!

Thanks

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Darren,

There are a few things going on that prevent the choices from displaying:

1) You are using the 'or' statement to essentially pick from 2 different lists; Survey123 will still treat that as one list and needs filtering values for all choices. You can solve this by using a fake value ('nope') where you have blanks currently

2) While I suggested using parenthesis, those aren't supported in the choice_filter at this time (apologies).  You can get around that by making your or statement the first statement OR by creating a calculate question that uses coalesce(${WetlandAcidity}, ${WetlandPermanence}) to get a combined value for lookup in place of the (${WetlandAcidity} or ${WetlandPermanence}).

3) You are using the same name (value) for multiple choices, these should be distinct values

DarrenSchouls
New Contributor II

I got it to work, thank you very much for your help James!

0 Kudos
JhoanUrquia
New Contributor

Hi James,

The IF statement is supported too? Im triyng to do a choice filter depending on the previous question. The column used for the choice filter would be conditioned.

Thnks a lot

0 Kudos