End a Survey Early in XLSForm: Consent and Screening
To end a survey early in XLSForm, put every question after the consent or screening question inside one group, and write the condition for carrying on, such as ${consent} = '1', in that group's relevant column. XLSForm has no "end survey" or "skip to end" command, so this one group does the job of a skip rule on every row. Every example below compiles with pyxform and ODK Validate, the check ODK Central runs when you upload a form.
How do I end the survey when the respondent does not consent?
Ask for consent, then open a group on the next row and close it on the last row of the form. The group's relevant condition decides whether anything inside is asked:
| type | name | label | required | relevant |
|---|---|---|---|---|
| select_one yes_no | consent | Do you agree to take part in this interview? | yes | |
| begin group | interview | Household interview | ${consent} = '1' | |
| integer | hh_size | How many people live in this household? | yes | |
| select_one yes_no | has_latrine | Does the household have a latrine? | yes | |
| end group | interview | |||
| note | end_refused | The respondent did not agree. Thank them and save the form. | ${consent} = '0' |
| list_name | name | label |
|---|---|---|
| yes_no | 1 | Yes |
| yes_no | 0 | No |
When the answer is No, the group is skipped and the next screen is the closing note, then the end of the form. The enumerator saves and sends it like any other interview, so the refusal is counted.
Three things make this work:
- The consent question sits outside the group. A group cannot depend on a question inside itself.
- Required questions in a skipped group do not block the form.
requiredonly applies to questions that are shown. - Skipped answers are blank in the submission. If the enumerator fills in three questions, goes back and changes consent to No, those three answers are not sent.
How do I end the survey when the respondent is not eligible?
Screening usually has more than one rule. Work the result out in a calculate row, then test that one field on the group. Here the survey is for women aged 15 to 49 who live in the household:
| type | name | label | required | relevant | calculation |
|---|---|---|---|---|---|
| select_one sex | resp_sex | What is the respondent's sex? | yes | ||
| integer | resp_age | How old is the respondent? | yes | ||
| select_one yes_no | lives_here | Does the respondent usually live in this household? | yes | ||
| calculate | eligible | if(${resp_sex} = '2' and ${resp_age} >= 15 and ${resp_age} <= 49 and ${lives_here} = '1', 1, 0) | |||
| begin group | women_module | Women's questionnaire | ${eligible} = 1 | ||
| select_one yes_no | ever_pregnant | Has she ever been pregnant? | yes | ||
| integer | live_births | How many live births has she had? | yes | ${ever_pregnant} = '1' | |
| end group | women_module | ||||
| note | end_screened | This respondent is not eligible. Thank them and save the form. | ${eligible} = 0 |
| list_name | name | label |
|---|---|---|
| sex | 1 | Male |
| sex | 2 | Female |
Keeping the rule in one calculate means the group and the closing note can never disagree, and the eligible column is in your data for the screening report. The XLSForm if statement guide covers and, or and nested conditions.
Keep the eligible calculate outside the group it controls. A calculate inside a skipped group is blank in the submission, so the one field that explains why the interview stopped would be empty for every screened-out respondent.
How do I end the survey at more than one point?
Open a new group at each stop point and close all of them at the end of the form. Each inner group inherits the conditions of the groups around it, so you never repeat a rule. This form stops after a refusal, and stops again when the household has no child under five:
| type | name | label | required | relevant |
|---|---|---|---|---|
| select_one yes_no | consent | Do you agree to take part in this interview? | yes | |
| begin group | after_consent | Household questions | ${consent} = '1' | |
| integer | hh_size | How many people live in this household? | yes | |
| select_one yes_no | has_under5 | Is there a child under 5 in the household? | yes | |
| begin group | after_under5 | Child questions | ${has_under5} = '1' | |
| integer | n_under5 | How many children under 5 live here? | yes | |
| select_one yes_no | child_vaccinated | Has the youngest child had any vaccination? | yes | |
| end group | after_under5 | |||
| end group | after_consent | |||
| note | end_early | The interview ends here. Thank the respondent and save the form. | ${consent} = '0' or ${has_under5} = '0' |
Group names must be different, and the end group rows close the groups in reverse order: the last one opened is the first one closed. For how groups and their conditions work in general, see skip logic in XLSForm.
How do I end the survey based on a select_multiple answer?
A select_multiple answer is a list of every option ticked, so test it with selected() and count-selected(), not =. This form only continues for households that keep at least one kind of livestock:
| type | name | label | required | relevant |
|---|---|---|---|---|
| select_multiple livestock | livestock | Which livestock does the household keep? | yes | |
| begin group | livestock_module | Livestock questions | count-selected(${livestock}) > 0 and not(selected(${livestock}, '0')) | |
| integer | n_animals | How many animals does the household own in total? | yes | |
| select_one yes_no | sold_animals | Did the household sell any animals in the last 12 months? | yes | |
| end group | livestock_module | |||
| note | end_no_livestock | This household keeps no livestock. Thank the respondent and save the form. | selected(${livestock}, '0') |
| list_name | name | label |
|---|---|---|
| livestock | 1 | Cattle |
| livestock | 2 | Goats or sheep |
| livestock | 3 | Poultry |
| livestock | 0 | None |
To require a minimum number of answers instead, change the group's condition to something like count-selected(${livestock}) >= 2. The guide to select_multiple skip logic explains selected(), and None of the above in XLSForm shows how to stop "None" being ticked together with other options.
How do I record why the interview ended?
Add one calculate outside every group that names the outcome. Refusals and screen-outs then arrive as ordinary submissions with a clear reason, which is what you need to report a response rate:
| type | name | label | required | relevant | calculation |
|---|---|---|---|---|---|
| select_one yes_no | consent | Do you agree to take part in this interview? | yes | ||
| integer | resp_age | How old is the respondent? | yes | ${consent} = '1' | |
| calculate | eligible | if(${consent} = '1' and ${resp_age} >= 18, 1, 0) | |||
| calculate | interview_result | if(${consent} = '0', 'refused', if(${eligible} = 0, 'not_eligible', 'completed')) | |||
| begin group | main_interview | Main interview | ${eligible} = 1 | ||
| select_one yes_no | has_phone | Does the respondent own a mobile phone? | yes | ||
| end group | main_interview | ||||
| note | end_result | Interview result: ${interview_result}. Thank the respondent and save the form. | ${eligible} = 0 |
In the export, interview_result has one value per submission, and a count of each value is your disposition table. Without it, an analyst has to work out the reason from which columns are blank.
Can I use a tick box for consent instead of Yes and No?
Yes. The acknowledge type shows a single tick box and stores OK when it is ticked. Put that value in the group's condition:
| type | name | label | relevant |
|---|---|---|---|
| acknowledge | agree | I have read the consent statement aloud and the respondent agrees to take part. | |
| begin group | after_agree | Interview | ${agree} = 'OK' |
| text | resp_name | What is the respondent's name? | |
| integer | resp_age | How old is the respondent? | |
| end group | after_agree | ||
| note | end_no_agree | No consent was recorded. Thank the respondent and save the form. | ${agree} != 'OK' |
The trade-off is in the data. An unticked box is blank, so a refusal and a question the enumerator never reached look the same. A Yes/No question records the refusal as its own value, which is the safer choice when refusals must be counted.
Common mistakes when ending a survey early
The first five messages are what pyxform and ODK Validate return, which is what you see when ODK Central, KoboToolbox or the XLSForm converter rejects the form:
| Mistake | Fix | Error you will see |
|---|---|---|
| The consent question is inside the group it controls | Move it above the begin group row | Cycle detected in form's relevant and calculation logic! |
No end group row at the end of the form | Add end group after the last question | Unmatched 'begin_group'. No matching 'end_group' was found for the name 'main'. |
| Two groups at the same level with the same name | Give each group its own name | the 'name' value 'main' is invalid. Questions, groups, and repeats must be unique within their nearest parent group or repeat |
| Field name mistyped in the condition | Match the name column exactly | Reference variables must contain a name from the 'survey' sheet. Could not find the name 'consnt'. |
${consent} == '1' | ${consent} = '1' | Encountered a problem with display condition for node |
${consent} = 'Yes' when the choice name is 1 | Compare with the choice name: ${consent} = '1' | No error, but the group never opens |
| The eligibility calculate is inside the skipped group | Move it above the begin group row | No error, but the value is blank for stopped interviews |
The last two compile and fail silently, so test both paths in preview: one interview that goes on and one that stops. For other messages, see common XLSForm errors, or paste your form into the free XLSForm validator.
The form cannot close itself or open a new blank form. After the closing note the enumerator reaches the normal end screen and saves the form. Say this in the note, as the examples do, so nobody wonders whether a short interview should be sent.
Does this work the same in ODK, KoboToolbox and SurveyCTO?
Yes. None of the three has an "end survey" action, and all three skip everything inside a group whose condition is false. What differs is where you type the condition:
| Platform | Where the condition goes |
|---|---|
| ODK (XLSForm) | relevant column of the begin group row |
| KoboToolbox Formbuilder | Select the questions, group them, then open the group's settings and add the rule under Skip Logic |
| KoboToolbox (XLSForm upload) | Same as ODK |
| SurveyCTO | relevance column of the begin group row |
The expressions themselves are the same on all three, so a form built with these examples moves between platforms by renaming one column for SurveyCTO.
Why end the interview in the form and not by instruction?
A printed rule like "if No, end the interview" depends on the enumerator stopping, and on them not filling in a few more questions out of habit. A group condition removes the choice: the questions are not there to answer. It also keeps the short interviews. Refusals and screen-outs are sent with a reason attached, so the team can report how many households were approached, how many refused and how many did not qualify, without a separate tally sheet.
You can describe the rule in plain language instead: "end the interview if the respondent does not consent or is under 18, and record the reason". LooprAI adds the group, the closing note and the result calculate, then compiles the form with pyxform before anything is saved, so an unmatched group or a mistyped field name never reaches your form.
Next: XLSForm skip logic →
Frequently Asked Questions
How do I end a survey early in XLSForm?
Put every question after the deciding question inside one group, and write the condition for carrying on in the group's relevant column, for example ${consent} = '1'. When the condition is false the whole group is skipped and the enumerator reaches the end of the form.
Is there an end survey or skip to end function in ODK?
No. ODK, KoboToolbox and SurveyCTO have no command that ends a form or jumps to the last screen. The standard method is a group with a relevant condition around the rest of the form, which skips all remaining questions with a single rule.
How do I end the form if the respondent does not consent?
Ask consent as a required select_one outside any group. Open a group on the next row with relevant ${consent} = '1' and close it after the last question. Add a note after the group with relevant ${consent} = '0' that tells the enumerator to save the form.
Will required questions stop the form from being saved after it ends early?
No. A required question only has to be answered when it is shown. Questions inside a group whose relevant condition is false are skipped, so the enumerator can finalize and send the form even though every question in that group is marked required.
Is a survey that ended early still submitted?
Yes. The enumerator saves and sends it like any other form, and it arrives with the skipped questions blank. Add a calculate outside the group that stores the outcome, such as refused or not_eligible, so these submissions can be counted and filtered in analysis.
How do I end a survey at several different questions?
Open a new group straight after each stop question and close all of them at the end of the form. Inner groups inherit the conditions of the groups around them, so each stop point needs only its own rule on one begin group row.
No Credit Card Required
Build the form first. Add hosting when you need it.
Start free with LooprAI, then deploy a managed ODK Central server or run DataSnap checks when your project is ready.
Automation handles the mechanical work.
Researchers decide what the evidence means.