A repeat group is added in the Survey Builder like any question, with the type Repeat group.
Set it up
- Say what each entry is, for example Household members.
- Under Questions for each entry, add the questions to ask for every member. Each one has the usual settings: answers, checks, and when to ask it.
- To fix the number of entries, write it under Number of entries. It can be an earlier answer, such as
${household_size}, or any expression, such ascount-selected(${crops})for one entry per crop chosen. Leave it empty to let the respondent add entries. - Set the most entries allowed. A repeat group holds at most fifty.
A repeat group inside a repeat group
A repeat group can hold another, so each member's plots are asked inside that member's entry. Choose Repeat group under Add a question in the outer group's list, and set it up the same way. Its number of entries can read the member's own answer, such as ${plot_count}, so each member gets as many plots as they said.
Repeat groups go three deep. Inside a repeat group, the most entries times the outer group's most entries can be at most a thousand, and the builder says so when they are more.
What an entry can hold
An entry is one screen, and every question in it can read the others. A condition, a choice that depends on an earlier answer, a rule and a label all read that entry's answers, those of each entry around it, and the rest of the interview's. So In school? can be asked only when this member is under eighteen, and a label can show each member's own name.
An entry can hold any question but a message test, a grid and where the interview began. Everything else fits. Calculations are worked out in order inside each entry, each reading the ones before it. Photos, signatures, recordings, files, lines and areas are taken and stored for their entry. A note shows text in each entry, piped with its answers, and holds no answer. A question's default is filled in when its entry is made, so position(..) as a default numbers the entries.
Read across the entries
An expression can read every entry with the functions XLSForms use:
count(${members})is the number of entries;sum(${acres}),max(${age})andmin(${age})work on one answer from each entry;count-non-empty(${phone})counts the entries that gave an answer;join(', ', ${name})joins them into one piece of text;indexed-repeat(${name}, ${members}, 1)reads one entry by its number;position(..)is the number of the entry a question is in, andposition(../..)that of the entry around it.
From outside a repeat group these read every entry. From inside a member's entry, sum(${acres}) adds up that member's plots only. When any entry left the answer blank, sum() gives no answer, as in ODK. Use coalesce(${acres}, 0) in a calculation inside the entry, and add that up, to count a blank as nought.
Outside its repeat group, a question asked in each entry can be read only through these functions. The builder says so as you type.
Where it can be answered
A repeat group needs a screen. The web link, data entry and the interviewer app show every entry on one page, a repeat group inside it too, and the web link does so without a connection. Text message, USSD and voice calls cannot carry one, and the launch review says so before collection opens.
Each entry is checked against its questions' rules when the interview arrives, at every depth, and its calculations are worked out again. An answer to a question the entry did not ask is refused, and so is a missing entry when the number is fixed.
In the data
The export comes in two layouts. One row per interview gives each entry and question its own column: members_1_member_age, members_2_member_age, and for a repeat group inside one, members_1_plots_2_crop. A file per repeat group gives a zip with a file for the interviews and one for each repeat group, a row per entry. Each row carries response_id and the entry numbers that join it to the row it belongs to, such as members_entry and plots_entry.
From an XLSForm
A begin repeat block imports as a repeat group, with its repeat_count, and one inside another comes in too, three deep. Calculations, hidden fields, photos and notes inside a repeat come in with it. A ${members}[position() = 2]/age filter is read as indexed-repeat(). A repeat count that reads the repeat itself, adding an entry while the last says there is another, lets the respondent add entries until done. Exporting writes the groups back as begin_repeat and end_repeat, one inside the other.