# Choice filter with an if where else is no filter?

**URL:** <https://forum.getodk.org/t/choice-filter-with-an-if-where-else-is-no-filter/26301>\
**Category:** Support\
**Created:** [May 1, 2020, 12:38am UTC](https://forum.getodk.org/t/choice-filter-with-an-if-where-else-is-no-filter/26301 "2020-05-01T00:38:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trialsize](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/trialsize/32/1633_2.png) [@trialsize](https://forum.getodk.org/u/trialsize)\
**Post date:** [May 1, 2020, 12:38am UTC](https://forum.getodk.org/t/choice-filter-with-an-if-where-else-is-no-filter/26301/1 "2020-05-01T00:38:50Z")

</div>

**1. What is the problem? Be very detailed.**  
Hoping to have an if statement in the choice\_filter where the else is to not apply any choice\_filter at all

**2. What app or server are you using and on what device and operating system? Include version numbers.**  
Latest ODK Collect

**3. What you have you tried to fix the problem?**

**4. What steps can we take to reproduce the problem?**

**5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.**

I have a question for an inspection type. In the following group I have a question for a category. If the inspection type = a, b, or c then the category should filter on the inspection type. However, if the inspection type is d or e, all categories should be available.

My choice\_filter looks like this:  
if(not(selected(${inspection\_type}, 'd')),if(not(selected(${inspection\_type},  
'e')),inspection\_type=${inspection\_type}, inspection\_type=''), inspection\_type='')

And the choices look like this:  
category category1 a  
category category2 a  
category category3  
category category4 b  
category category5 c  
category category6 a  
category category7  
category category8  
etc.  
I'm hoping if inspection type is a, b, or the choices available are filtered as above. However if inspection type is d or e then all 8 categories are available. Unfortunately, the way my choice\_filter is written currently only category3, category7, and category8 are available due to the else setting the filter to an empty string.

---

<div class="post-metadata">

**Author:** ![noel\_cartong](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/n/e79b87/32.png) [@noel\_cartong](https://forum.getodk.org/u/noel_cartong)\
**Post date:** [May 2, 2020, 11:11am UTC](https://forum.getodk.org/t/choice-filter-with-an-if-where-else-is-no-filter/26301/2 "2020-05-02T11:11:42Z")

</div>

If you attach a section of the xlsform it will be easier to troubleshoot and give you a fully functioning example but the general idea should be something more like this...

inspection\_type=${inspection\_type} or selected(${inspection\_type},'d') or selected(${inspection\_type},'e')

Thankfully the choice\_filter functionality has a significant amount of flexibility and should be able to do what you want without needing any if() statements.

---

<div class="post-metadata">

**Author:** ![trialsize](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/trialsize/32/1633_2.png) [@trialsize](https://forum.getodk.org/u/trialsize)\
**Post date:** [May 4, 2020, 2:25pm UTC](https://forum.getodk.org/t/choice-filter-with-an-if-where-else-is-no-filter/26301/3 "2020-05-04T14:25:12Z")

</div>

Ah, I see! I figured by specifying 'd' and 'e' in the choice filter it would not return any choices at all since they were not specified options on the choices tab. This works great, thank you!

For anyone else needing a visual example see attached.[choice\_filter\_test.xlsx](https://forum.getodk.org/uploads/short-url/lz7j6AeaUwTsr2FD8t4Vkuqvuuq.xlsx) (10.5 KB) [choice\_filter\_test.xml](https://forum.getodk.org/uploads/short-url/jGuOXsJfd5ea9kh1eu48vTmBOKV.xml) (4.2 KB)

---

<div class="post-metadata">

**Author:** ![jd2701](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/j/f19dbf/32.png) [@jd2701](https://forum.getodk.org/u/jd2701)\
**Post date:** [September 15, 2022, 3:33pm UTC](https://forum.getodk.org/t/choice-filter-with-an-if-where-else-is-no-filter/26301/4 "2022-09-15T15:33:21Z")

</div>

Hi,  
In my case, I was use a regex in the choice\_filter based on a calculation.  
Like this example :  
param\_1='some value' and regex(param\_2, ${a\_calculation})

And my calculation `a_calculation` can used some if statement
