# Constraints between an integer and multiple choices

**URL:** <https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383>\
**Category:** Support\
**Created:** [March 10, 2017, 12:18pm UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383 "2017-03-10T12:18:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Tony](https://forum.getodk.org/u/Tony)\
**Post date:** [March 10, 2017, 12:18pm UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/1 "2017-03-10T12:18:45Z")

</div>

Hi everyone,  
I am having a problem like this: I want to put a constraint between an  
integer input and a choice in multiple choice question.

Q1. How much do you spend on food everyday? \_\_\_\_\_\_\_\_\_

Q2. Please select the range ?

a. Less than 10usd  
b. Between 10usd and 20usd  
c. More than 20usd

I want to put a constraint that warn the surveyors in case they input 50usd  
and select a or b. Is there anyway to do that.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![DAGBEMAMBOU](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/d/e95f7d/32.png) [@DAGBEMAMBOU](https://forum.getodk.org/u/DAGBEMAMBOU)\
**Post date:** [March 10, 2017, 2:29pm UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/2 "2017-03-10T14:29:16Z")

</div>

Hi, Tony.  
Try this (assuming that your Q2 is select\_one question):  
put the following expression  
( .='a' and ${Q1\_name}\<10 ) OR ( .='b' and ${Q1\_name}\>=10 and  
${Q1\_name}\<=20 ) OR ( .='c' and ${Q1\_name}\>20 )  
in the constraint column of Q2  
Note that in this expression, "." is put for ${Q2\_name}.  
Hope that helps.  
Best,

> **···**
>
> Le vendredi 10 mars 2017 13:18:51 UTC+1, Tony a écrit : \> \> Hi everyone, \> I am having a problem like this: I want to put a constraint between an \> integer input and a choice in multiple choice question. \> \> Q1. How much do you spend on food everyday? \_\_\_\_\_\_\_\_\_ \> \> Q2. Please select the range ? \> \> a. Less than 10usd \> b. Between 10usd and 20usd \> c. More than 20usd \> \> I want to put a constraint that warn the surveyors in case they input \> 50usd and select a or b. Is there anyway to do that. \> \> Thank you very much. \>

---

<div class="post-metadata">

**Author:** ![Tony](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Tony](https://forum.getodk.org/u/Tony)\
**Post date:** [March 11, 2017, 1:53am UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/3 "2017-03-11T01:53:20Z")

</div>

It works great thank you.

---

<div class="post-metadata">

**Author:** ![debu\_odk](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/debu_odk/32/1876_2.png) [@debu\_odk](https://forum.getodk.org/u/debu_odk)\
**Post date:** [July 8, 2017, 3:01pm UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/4 "2017-07-08T15:01:45Z")

</div>

Hi Tony,

as i user of ODK, i am asking one thing about your question and answer of Amal. May i know please which element has been used for the syntax as Amal replied. I used "selected" but it didn't work...

Could you pleased reply me how you did?

Dev

---

<div class="post-metadata">

**Author:** ![debu\_odk](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/debu_odk/32/1876_2.png) [@debu\_odk](https://forum.getodk.org/u/debu_odk)\
**Post date:** [July 9, 2017, 9:36pm UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/5 "2017-07-09T21:36:39Z")

</div>

First posted by Tony

Hello !

I am having a problem like this: I want to put a constraint between an  
integer input and a choice in multiple choice question.  
q1. How much do you spend on food everyday? \_\_\_\_\_\_\_\_\_

q2. Please select the range ?

1. Less than 10usd
2. Between 10usd and 20usd
3. More than 20usd

I want to put a constraint that warn the surveyors in case they input 50usd  
and select 1 or 2. Is there anyway to do that.

I just copied that I faced the similar case and I follow as given instruction using the xls syntax “(q2='1' and ${q1}\<10 ) or (q2='2' and ${q1}\>=10 and q2=2 and ${q1}\<=20) or ( q2='3' and ${q1}\>20)” BUT I could not get success so could you please help me to make right syntax…

Thank you very much.

Dev Maharjan

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [July 9, 2017, 9:29pm UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/6 "2017-07-09T21:29:27Z")

</div>

Hi @debu_odk  
I think it should be `(selected(., 'q2a') and /data/q1 < 10) or (selected(., 'q2b') and /data/q1 > 10 and /data/q1 < 20) or (selected(., 'q2c') and /data/q1 > 20)`  
look at the xls file and the form:  
[test.xml](https://getodk.b-cdn.net/uploads/default/original/2X/9/9ee4a72de0ad78151e028fbe2d972771d9b9592c.xml) (1.4 KB)  
[test.xlsx](https://getodk.b-cdn.net/uploads/default/original/2X/0/02662522a6e2d1c1127faf62249cf4f48e89a438.xlsx) (7.6 KB)

Regards,  
Grzegorz

---

<div class="post-metadata">

**Author:** ![Dev](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/dev/32/3449_2.png) [@Dev](https://forum.getodk.org/u/Dev)\
**Post date:** [July 10, 2017, 4:30am UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/7 "2017-07-10T04:30:58Z")

</div>

Dear Grzegorz,

Thank you very much for assisting me on the matter unfortunately it didn't work what i expecting when i tested and tried uploading. I got the results which i have attached...but i am not much aware about xml codes... I hope you can develope new syntax for it.

Regards..  
Dev Maharjan

 ![image](https://getodk.b-cdn.net/uploads/default/original/2X/3/37f2b7abb64404f9c8d40a714a9713442cf43d9c.jpg)

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [July 10, 2017, 8:03am UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/8 "2017-07-10T08:03:31Z")

</div>

It works well if you use this form in Collect app I don't know why it doesn't work in Enketo preview and I'cant help because I am focused only on ODK Collect. Do you want to use this form in Collect or Enketo?

Regards,  
Grzegorz

---

<div class="post-metadata">

**Author:** ![debu\_odk](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/debu_odk/32/1876_2.png) [@debu\_odk](https://forum.getodk.org/u/debu_odk)\
**Post date:** [July 10, 2017, 10:48am UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/9 "2017-07-10T10:48:53Z")

</div>

Dear Grzegorz,

Thank you very much for your kind response. I tried in Kobotoolbox...

Regards

Dev

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [July 10, 2017, 11:04am UTC](https://forum.getodk.org/t/constraints-between-an-integer-and-multiple-choices/6383/10 "2017-07-10T11:04:09Z")

</div>

in that case you should report this fact to Kobotoolbox as I said it's ok if I use the Collect app.

Regards,  
Grzegorz
