Fix the XLSForm Dependency Cycle Error (ODK, Kobo)
The error "Dependency cycles amongst the xpath expressions in relevant/calculate" means a row depends on itself, and the fix is to remove that row's own name from its logic: write selected(${pests}, '-96') on the pests_other row, not selected(${pests_other}, '-96'). Newer versions of ODK Validate word the same error as "Cycle detected in form's relevant and calculation logic!". Every fixed example below compiles with pyxform and ODK Validate, the check ODK Central and KoboToolbox run on upload.
What does the dependency cycle error mean?
A form works out its answers in order: a calculation needs its inputs first, and a question needs its relevant condition settled before it can be shown. A cycle is a loop in that order. Row A needs row B, and row B needs row A, so neither can go first. The shortest loop is one row that needs itself.
You will see one of two wordings, depending on how old the validator is:
ODK Validate Errors:
>> Something broke the parser. See above for a hint.
Dependency cycles amongst the xpath expressions in relevant/calculate
Result: Invalid
ODK Validate Errors:
>> XForm is invalid.
: Cycle detected in form's relevant and calculation logic!
The following nodes are likely involved in the loop:
${pests_other}
Result: Invalid
They are the same error. The newer one is more useful because it names the rows involved.
How do I find the row that causes the cycle?
Start from the names in the message, then search the survey sheet.
- One name listed. That row refers to itself. Open it and look for its own name inside
${...}in therelevant,calculationorrequiredcolumn. If the name belongs to a group, a question inside the group is used in the group's ownrelevant. - Several names listed. The rows form a chain. Follow it: the first row's logic mentions the second, the second mentions the third, and the last one points back to the first.
- No names listed (old wording). Search each logic column for rows that mention their own name first. That is the cause in most forum threads about this error. If you find none, check your most recent calculate rows for pairs that mention each other.
Only relevant, calculation and required take part. A question's own name in its constraint does not cause a cycle.
The cycle is checked on the form's logic, not on what an enumerator types. A loop that could "never happen in practice" is still rejected, so the form has to be rewritten; there is no setting that turns the check off.
Why does my "Other, specify" question cause a cycle?
Because the relevant was copied onto the specify row with the specify row's own name in it. The question says "show me only if I contain -96", which depends on itself. Point it at the select question above it:
| type | name | label | relevant |
|---|---|---|---|
| select_multiple pests | pests | Which crop pests did you see this season? | |
| text | pests_other | Please specify the other pest | selected(${pests}, '-96') |
| list_name | name | label |
|---|---|---|
| pests | 1 | Fall armyworm |
| pests | 2 | Stem borer |
| pests | 3 | Locusts |
| pests | -96 | Other (specify) |
The broken version has selected(${pests_other}, '-96') in the same cell. The names differ by a suffix, which is why it survives a quick read. The full pattern, including select_one, is in "Other, please specify" in XLSForm.
How do I fix a calculation that refers to itself?
Give the calculation only inputs, never its own name. The usual case is a running total written the way a programmer would write it: ${total_exp} + ${health_exp} in the total_exp row. A calculate cannot add to its previous value. List every part instead:
| type | name | label | calculation |
|---|---|---|---|
| integer | food_exp | How much did the household spend on food last week? | |
| integer | health_exp | How much did the household spend on health last week? | |
| integer | school_exp | How much did the household spend on schooling last week? | |
| calculate | total_exp | coalesce(${food_exp}, 0) + coalesce(${health_exp}, 0) + coalesce(${school_exp}, 0) | |
| note | show_total | Total spending last week: ${total_exp} |
coalesce(${x}, 0) treats a skipped question as 0, so one empty answer does not blank the whole total. More patterns are in the XLSForm calculations guide.
How do I fix two calculations that depend on each other?
Rewrite one of them from the answers the enumerator types. Here the broken form had net_sales as ${sales} - ${fee} and fee as ${net_sales} * 0.1. Each needs the other. The market fee is really 10% of sales, so work it out from sales:
| type | name | label | calculation |
|---|---|---|---|
| integer | sales | What were the trader's total sales yesterday? | |
| calculate | fee | round(${sales} * 0.1, 0) | |
| calculate | net_sales | ${sales} - ${fee} | |
| note | show_net | Sales after the market fee: ${net_sales} |
Longer chains work the same way. A relevant counts too: if question A is shown only when calculate C equals 1, and C is worked out from A, that is a loop even though only one of the rows is a calculate. Draw the chain on paper, find the arrow that points backwards, and replace that one reference.
Why does a group's relevant cause a cycle?
Because a group's relevant applies to every question inside it. If the gate question sits inside the group, it can only be asked when it has already been answered. The error names the group, not the question. Move the gate above begin group:
| type | name | label | relevant |
|---|---|---|---|
| select_one yes_no | has_children | Are there children under 5 in the household? | |
| begin group | child_section | Children under 5 | ${has_children} = '1' |
| integer | n_children | How many children under 5? | |
| select_one yes_no | any_sick | Was any of them sick in the last 2 weeks? | |
| end group | child_section |
| list_name | name | label |
|---|---|---|
| yes_no | 1 | Yes |
| yes_no | 0 | No |
The same rule holds for a repeat with a relevant. See skip logic in XLSForm for group-level conditions.
How do I keep a running total in a repeat without a cycle?
Read the typed question from the earlier instance, and put the total outside the repeat. What fails is a calculate that reads its own value from the previous instance, such as indexed-repeat(${running}, ${delivery}, position(..) - 1) + ${bags} in the running row. The validator treats running as depending on running.
| type | name | label | calculation | relevant |
|---|---|---|---|---|
| begin repeat | delivery | Delivery | ||
| integer | bags | How many bags were delivered? | ||
| calculate | prev_bags | indexed-repeat(${bags}, ${delivery}, position(..) - 1) | ||
| note | show_prev | The delivery before this one had ${prev_bags} bags. | position(..) > 1 | |
| end repeat | delivery | |||
| calculate | total_bags | sum(${bags}) | ||
| note | show_bags | Total bags delivered: ${total_bags} |
prev_bags depends on bags, which is typed, so there is no loop. sum(${bags}) sits after end repeat, where it adds every instance. See sum values in a repeat group and indexed-repeat() for both functions.
Do not move sum(${bags}) inside the repeat to get around the error. It compiles, but inside its own repeat ${bags} means the current instance only, so the "total" is just that one delivery.
Which columns can cause a cycle, and which cannot?
relevant, calculation and required can. constraint cannot, so both . >= 0 and ${age} >= 0 are accepted in the age row, although . is the normal way to write it. once() does not exempt a calculation either: once(if(${draw} = '', random(), ${draw})) is rejected, while once(random()) does the same job.
| type | name | label | constraint | calculation |
|---|---|---|---|---|
| integer | age | How old is the respondent? | . >= 0 and . <= 120 | |
| calculate | draw | once(random()) | ||
| note | show_draw | Random draw for this interview: ${draw} |
Common causes and the fix for each
Each broken version was run through ODK Validate; the last column is the name it printed under "likely involved in the loop".
| Row and what you wrote | Write instead | Name in the error |
|---|---|---|
pests_other relevant: selected(${pests_other}, '-96') | selected(${pests}, '-96') | ${pests_other} |
total calculation: ${total} + ${amount} | Add the inputs: ${amount} + ${other_amount} | ${total} |
net = ${income} - ${tax} and tax = ${net} * 0.1 | tax = ${income} * 0.1 | ${tax} and ${net} |
Group g relevant: ${has_child} = '1', with has_child inside g | Move has_child above begin group | ${g} |
running calculation reads ${running} from the previous repeat instance | Read a typed question; sum() after end repeat | ${running} |
nm required: ${nm} = '' | yes | ${nm} |
rand_id calculation: once(if(${rand_id} = '', random(), ${rand_id})) | once(random()) | ${rand_id} |
For other upload messages, see common XLSForm errors, or paste the form into the free XLSForm validator.
Does this work the same in ODK, KoboToolbox and SurveyCTO?
The rule is the same everywhere: a form's logic may not loop. Where you meet the error differs.
| Platform | Where you meet it |
|---|---|
| ODK (pyxform, XLSForm Online, Central) | On conversion or upload, as "ODK Validate Errors" with one of the two wordings above |
| KoboToolbox | On preview or deploy: "your form cannot be deployed because it contains errors", followed by the ODK Validate text |
| Older ODK Collect | On opening a blank form that was never validated, with the "Dependency cycles" wording |
| SurveyCTO | Skip logic goes in a column named relevance. A row that refers to itself there is the same mistake, with the same fix |
Why the validator is right to refuse the form
A loop has no correct answer. If a total includes itself, or a question is shown only when it is already answered, any value the app picked would be a guess. Refusing the form on upload costs a few minutes at the desk. A form that looped during an interview would cost the interview.
Describe the rule in plain language instead: "ask for the other pest only when Other is ticked, and show total spending on food, health and school". LooprAI writes the rows and compiles the form with pyxform and ODK Validate before anything is saved, so a row that depends on itself never reaches your form.
Next: common XLSForm errors →
Frequently Asked Questions
What does 'Dependency cycles amongst the xpath expressions in relevant/calculate' mean?
A row in your form depends on itself, either directly or through other rows. The form cannot decide which value to work out first, so ODK Validate rejects it. Newer versions word it as 'Cycle detected in form's relevant and calculation logic' and list the rows involved.
How do I find which question causes the dependency cycle?
Read the names after 'The following nodes are likely involved in the loop'. One name means that row mentions itself in its relevant, calculation or required column. Several names mean a chain between those rows. With the older message, search for rows that contain their own name.
Why does my Other specify question give a dependency cycle error?
Its relevant tests its own name, usually after a copy and paste: selected(${pests_other}, '-96') on the pests_other row. Change it to test the select question above it, selected(${pests}, '-96'), so the text box depends on the list and not on itself.
Can a calculate refer to itself to keep a running total?
No. A calculation such as ${total} + ${amount} in the total row is a cycle, and wrapping it in once() does not help. Add the input questions directly, or inside a repeat use sum() on the typed question after the end repeat row.
Does using a question's own name in its constraint cause a cycle?
No. Constraints are not part of the cycle check, so ${age} >= 0 in the age row compiles, although a dot is the usual way to write it. The columns that can form a cycle are relevant, calculation and required.
Why does the cycle error name a group instead of a question?
The group's relevant uses a question that sits inside the same group. A group's condition applies to everything in it, so that question would decide whether it is asked. Move the question above the begin group row and the error goes away.
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.