Multiple constraints using AND and OR

Hello,

I am building a form using excel that I will then upload on my server and use ODK Collect.

I have a question in the form the requires multiple constraint as follow:
You cannot select "Do not know" and any other option
You cannot select "Decline to answer" and any other option
You can select a max of 3 options.
I am using the following syntax but it appears to be wrong.

not(selected(.,"do_not_know") and count-selected(.) >1) or (not(selected(.,"decline_to_answer") and count-selected(.) >1)) and (count-selected(.)<=3)

Could you advice? Thank you very much!!

Hi @Alberto_Gualtieri something like this works well:
not(selected(., ‘do_not_know’)) and not(selected(., ‘decline_to_answer’)) and count-selected(.) <4

3 Likes

https://docs.opendatakit.org/form-logic/ also has a lovely write up about form logic!

3 Likes

This test will fail (ie return false) if you select 'do_not_know', or if you select 'decline_to_answer', which will effectively makes these two options invalid (!). Try this instead:

if(selected(., ‘do_not_know’) or selected(., ‘decline_to_answer’), count-selected(.)=1, count-selected(.)<=3)

3 Likes

Thank you all! The syntax works @Xiphware

To be perfectly fair, Grezegorz's solution is logically 100% correct, if you take your description of the problem literally; that is: "You cannot select 'Do not know' and any other option. You cannot select 'Do not know' and any other option. ...". But, at least my interpretation, is that what you probably really meant to say was "If you select 'Do not know' you cannot select any other option. And, if you select 'Decline to answer' you (also) cannot select any other option. Otherwise yer limited to at most 3 options. :slight_smile:

Which is to say, be careful what you ask for... :wink:

3 Likes