XLSForm Skip Logic, Constraints and Calculations: A Practical Guide for KoboToolbox and ODK
The relevant, constraint and calculation columns explained with copy-ready examples, plus the errors that trip up most KoboToolbox and ODK users.
XLSForm is the standard behind KoboToolbox, ODK and SurveyCTO. You design your form in an Excel workbook, upload it, and the platform turns it into a mobile form. Once you understand a handful of columns, you can build forms far more powerful than any drag-and-drop builder allows.
This guide covers the four columns that control how a form behaves: relevant, constraint, required and calculation. Every example uses the same syntax across all three platforms.
The basics: the survey and choices sheets
An XLSForm has two core sheets. The survey sheet lists your questions, one per row, with type, name and label columns. The choices sheet lists answer options for select questions, linked by a list_name.
survey sheet
type name label
select_one yesno consent Do you agree to take part?
integer age How old are you?
select_one yesno has_biz Do you own a business?
text biz_type What type of business?
choices sheet
list_name name label
yesno yes Yes
yesno no No
You refer to the answer of another question with ${question_name}, which is the key to everything below.
1. Skip logic with the relevant column
The relevant column holds a condition. The question is shown only when the condition is true. To show biz_type only to business owners:
name relevant
biz_type ${has_biz} = 'yes'
Note that you compare against the choice name (yes), not the label (Yes), and text values go in single quotes.
Common relevant patterns
| Goal | Expression |
|---|---|
| Adults only | ${age} >= 18 |
| Two conditions | ${has_biz} = 'yes' and ${age} >= 18 |
| Either condition | ${status} = 'student' or ${status} = 'unemployed' |
| Option ticked in a select_multiple | selected(${sources}, 'borehole') |
| Option NOT ticked | not(selected(${sources}, 'borehole')) |
| "Other, specify" follow-up | selected(${sources}, 'other') |
| Question was answered | ${phone} != '' |
Tip: to skip a whole section, put the condition on a begin_group row. Every question inside the group inherits it, so you don't have to repeat the condition on each question.
The consent pattern
Wrap the whole interview in a group that only appears when consent is given:
type name relevant
begin_group main ${consent} = 'yes'
... ...
end_group
2. Validation with the constraint column
A constraint rejects answers that break a rule. Inside a constraint, a dot (.) means "this question's answer". Pair it with a constraint_message so the enumerator knows what went wrong.
name constraint constraint_message
age . >= 15 and . <= 100 Age must be between 15 and 100
hh_size . >= 1 and . <= 30 Household size must be 1 to 30
children . <= ${hh_size} Cannot exceed household size
phone regex(., '^0[17][0-9]{8}$') Enter a 10-digit number, e.g. 0712345678
For a select_multiple, count-selected(.) <= 3 limits respondents to three choices, and not(selected(., 'none') and count-selected(.) > 1) stops "None" being ticked alongside other options.
3. The required column
Put yes in the required column for questions that can't be skipped. Add a required_message for a friendlier prompt. Be selective: making every question required frustrates respondents and invites made-up answers. Instead, give sensitive questions explicit "Don't know" and "Prefer not to say" options.
4. Calculations
A row of type calculate computes a value that isn't shown on screen but is saved with the data. Its formula goes in the calculation column.
type name calculation
calculate hh_total ${adults} + ${children}
calculate age_years int((today() - ${dob}) div 365.25)
calculate income_wk ${income_month} div 4.33
You can display a calculated value in a later label, for example You said your household has ${hh_total} members. Is that correct?, which is a simple, powerful consistency check.
Common errors (and fixes)
- "Unknown question ${xyz}" or "invalid reference": the name is misspelt, or the question it refers to doesn't exist. Names are case-sensitive.
- The question never appears: you compared against the label instead of the choice name, or forgot quotes around text values.
- Using = with select_multiple:
${sources} = 'borehole'only matches when borehole is the only option ticked. Useselected()instead. - Constraint blocks valid answers: check whether you used
andwhere you meantor, and test the boundary values. - Duplicate names: every
namemust be unique across the whole form, including inside groups. - Smart quotes from Word: curly quotes ’ ’ break expressions. Type quotes directly in Excel.
Test before you deploy
Always preview your form (Kobo's Enketo preview or ODK's form preview), then walk through every path: answer "No" to consent, enter boundary values like 15 and 100, and tick "Other". Submit a few test records and download the data to check the export looks the way your analysis needs. Then delete the test records before real collection begins.
Form throwing errors, or too complex to build yourself? We build and fix XLSForms for KoboToolbox, ODK and SurveyCTO, from skip logic and validation to repeat groups, choice filters and multiple languages.
Need your questionnaire built properly?
We design and test data collection tools on Google Forms, Microsoft Forms, KoboToolbox, ODK and SurveyCTO. Free quote within 24 hours.
Get a free quote →