Counting error in repeat (calculated counter)

KoboCollect seems to act up in the following situation:

  • Calculate questions pull class numbers grade by grade (from a csv file)
  • A select yes/no question asks if all these numbers are still correct
  • If the answer is ‘no’, it is asked for each grade, whether the number is correct
  • If the answer is ‘no’ again for a certain grade, an integer question is asked to get the correct number of classes in this grade
  • Then, a repeat loop (per grade) is asking for certain details on each class

Everything works well, except one goes back and changes an answer. For instance, if one selects ‘no’ to “all correct?” and “grade correct?” in order to correct the pulled “4” and enters a “2”, the repeat loop is done twice. But if one says ‘yes’ first, then goes one step back and changes this to ‘no’, the repeat loop is done 4 times (even though a temporary note question confirms a “2”)!?!?

Any idea, why the calculation isn’t updated?

Could you share the related extract of your form and your csv file, please?

1 Like

Sure! Thanks for the quick response.
facilities_xx_extract.csv (7.3 KB)
MDCv1_8_0-DataTest-XX_extract.xlsx (51.8 KB)

Sorry, to facilitate support, we would need a complete extract/example, please. At the moment there are a lot of references not in the file sent. Preferably even without the .csv pulldata (replaced by fixed or entered values). Best would be that your XLSForm extract/example is able to pass the Online validator, please.

In addition, a screenshot for the counter problem might help.

Can you also tell, which tool (Kobo/ODK Collect or Enketo) and server you are using, please?

1 Like

OK, I have started over and reduced the original form to the minimum, same for the respective csv file. It is running (with the described issue) on KoboToolbox

facilities_xx_extract.csv (1.8 KB)
MDCv1_8_0-DataTest-XX_extract-compl.xlsx (32.2 KB)

1 Like

Dear @wroos

Did you see the files? Are you able to reproduce the issue?

Any idea about the potential reason, so that we can think of further experiments and tests?

Kind regards
York

Sorry, it is difficult to understand this rather complex form, and I also had to adapt it before (choice list and deactivate appearance) to get it working.
I made a new version which is better to test, now showing all former calculate types too. (I changed the type and sometimes added a label). newMDCv1_8_0-DataTest-XX_extract-compl.xlsx (27.9 KB).

I think, there are several problems:

  • The core problem seems the calculation in line 12. Review and test, how I changed it, please. In Kobo/ODK calculations are not filtered by relevants! And in Enketo, as far as I know, currently non-relevant (invisible) variables may still be “counted” in calculations. (This might change soon.)
  • You have multilevel update dependencies, but some are not fully covered at the dependent questions. For ex. the yes/no select in line 10 is not reset to empty if you change the initial select. You may need to add the leading variable somehow in the calculation (etc.) to trigger an update.
  • There seems a problem with the appearance in line 5.
  • What is the difference between the questions in line 8 and line 10?
  • Avoid styling format elements in labels and other textual, e.g. # or _ or masked them with \. See e.g. lines 14-16.

I trust these hints and the full visible test version will help you to adapt the form to your requirements. You might need to temporarily deactivate some relevants (e.g. by changing the column name to XX…) to check for the dependency optimisation.

Dear @wroos

Thank you SO MUCH for your analysis. Very much appreciated, although I still can’t see the issue resolved.

Focusing on the “core problem” (calc in line 12), please note that I had changed that into if(${classes_pp_new}!=‘’,${classes_pp_new},${classes_pp_pull}), when experimenting. The original formula, which was/is reflecting the actual logical forward most directly, was: if(${situationdata_check_class}=‘y’,${classes_pp_pull},if(${classes_pp_check}=‘y’,${classes_pp_pull},${classes_pp_new}))

In any case, your version if(${classes_pp_check}=‘n’,${classes_pp_new},${classes_pp_pull}) doesn’t show any change (when I am testing it here: KoboToolbox

For instance, if one choses ‘n’ in the first step (are the numbers of classes for ALL grades, not just pp, still correct?) and ‘y’ also in the second step (is the number of pp classes still correct?), but then goes back and changes this to ‘n’, then…

…it seems to work, if I go back just from the next (usually invisible) question

…but it doesn’t work, if I go to the next visible question (i.e. the first enrolment date selection in line 23) and THEN go back to change the second confirmation step to ‘n’ and consequently enter a 2 then – in this case, the counter for entering the (should be 2) classnames remains on 4 (in the background), so that the form asks for 4 classnames (and later also asks for enrolment dates for 4 pp classes).

Do I miss to see the obvious? For me, going back and ensuring a ‘n’ (confirmation step 1), a ‘n’ (confirmation step 2) and 2 (classes_pp, used as the repeat counter then), should really work. There is no old wrong field values which could have an impact, are there? Is the repeat counter defined, when one “passes by” it in the first round and not fetched afresh, if one passes by it the second time, after the value of the counter has been changed??

I am afraid, you probably need to test it in more detail, and step-by-step.

If there is a logic depency, it needs to referenced in the calculation (tree). It seemed for me that (in Enketo) the non-relevant (previous) newPPvalue is still evaluated in your calculation. You can check this, please, by reducing the count calculation to: newPPvalue != ‘’ and move back and change yes to no. You may have a look here, please Feedback needed: Enketo relevance change to align with ODK Collect - Betas - ODK Forum.

I am sorry, I am too busy to continue here. Maybe, @Kal_Lam and the community can take over, please.