Constraint the answers based on previous answer

I have two questions Q1 and Q2.

Q1. In what time of the day are you drinking this drink? (SA)

  1. In the morning, when I wake up
  2. In the morning during breakfast
  3. In the morning, after breakfast
  4. During lunch time
  5. In the afternoon, after lunch
  6. During dinner
  7. At night after dinner

Q2. Do you take it with food/snack? (SA)

  1. Yes
  2. No

If respondent choose Code 2 or 4 or 6 in Q1, he or she need to choose Code 1"Yes" in Q2. If not show error message.
If respondent don't choose any of 2 or 4 or 6 he or she can choose "Yes" or "No" in Q2.

How to do it?

I am using Excel file (XLSform) with KOBO.

Hi Naylinsoe

You can do this in many ways.
First, you could use a note at the end of q2 that had the condition/relevance if Q1 = 2, 4 or 6 and Q2 = No then display note "You must go back and select the correct choice" or something like that. Make the note required so that a user cannot continue without selecting the correct choice combination in the previous questions.

Alternatively, you could add a calculate function at the end of question 1 where you assign a value to calc if 2,4 or 6 are selected. You should then use the value of this calculation to add a constraint after question 2 for what choices a user can select.

If my explanations are not clear please let me know and I illustrate it better.


Here you go: selectTest.xlsx (6.9 KB)

You can learn more here:


1 Like

hi @naylinsoe try this sample file and see if this is what you are looking for.
constraint_2017.xlsx (40.9 KB)

1 Like

Your form is best for understanding ODK.

1 Like

I have read a lot about your experience. I have a question if you can help me with. in the excel form, i have two questions: q1: what is the number of books in the school warehouse?
q2: what is the number of boxes in the public warehouse?
both answers should be identical. Now, how can i ask to explain if the answers do not match.

Hi @Mosab_English

something like this: relevant.xlsx (5.9 KB) ?

The formula works well, but is there another formula that says the number of the second question must be the same number of the first one

Yes, you need to use constraint
Here is an example: constraint.xlsx (5.9 KB)

I would like to inquire about the calculation matter. I want ask a question that requires to select from (yesnolist) and the answer will be yes or no or something else. Now, the question is "Is there a formula for each question to calculate the answer as number. For example, if the answer will be (yes), the calculation will be (2) and if the answer is (no), the calculation will be (0) and so on. If there is such calculation, would you please clarify this point in the test excel sheet attached. test (calcuation).xls (27 KB)

1 Like