Problems with repeat count

What is the problem? Please be detailed.
I am scripting a HH survey where I need to know the water consumption in liters per person per day. To get the total volume used by a house hold, I need to know the different types of the containers used for fetching water and how many times those containers are filled in a day. So I want the survey to calculate this and sum it up. I then need this sum to be divided by the number of people in the HH.

What ODK tool and version are you using? And on what device and operating system version?
I am using ONA version on Samsung phone with Android OS
What steps can we take to reproduce the problem?

What you have you tried to fix the problem?
I have used repeat-count to script this but it gives me an error as attached.
I also want to be helped on which code to sum up volumes from different containers. I used sum(nodeset) but I am not sure of this.
Anything else we should know or have? If you have a test form or screenshots or logs, attach here.
I have attached the error and the section of the scriptOna_support.xlsx (11.0 KB)

This type of error is due to multiple repeat loop i.e repeat inside the another repeating group. To overcome this error you need to use indexed-repeat() function.
If your form has such multiple repeat loop use indexed-repeat() function.
Here you can find the syntax for indexed-repeat() function.
If you can provide the xls form with multiple repeat I can help you too.

1 Like

No need to use indexed-repeat() nor repeat_count (though fine if you want to).

You were nearly there. The main issue with your form was the sum() formula. This should be sum(${volume}). See functioning version (with a few other changes) attached: water-consumption-survey.xlsx (17.1 KB) and live here (temporary link).

If you'd like to avoid the NaN (though I think it is actually helpful to keep it in this case), you could add another calculation inside the repeat that uses if() to set the value to 0 if volume has not yet been calculated. Then sum(${thatnewcalculation}) instead.

Good luck with the KAP survey from an old WASH person!

P.S. fwiw, unsollicited and knowing this is just a draft, WASH-technically, I would change the wording of the label of no_times.


Dear Pujan,

Thanks for your response, please find attached the excel file. I will really appreciate if you could fix for me the indexed-function in this mini survey.


Best regards.

water-consumption-survey.xlsx (20.1 KB)

This form have only one repeating group. Is this the complete form?
Please provide me the full form with nested repeating group.

Hello @Kur_Peter,

Sorry for late response . I am Presuming the problem is still open. The recent form you have provided is not complete I think, reason being there is no variable with the name not_transport in the form where as you are facing the problem at that variable and the problem was in relevant condition which is missing in the form you have attached. Seeing the screenshot of the error I think you are referring a variable which is inside the repeat group from outside that repeat group. The app has an ambiguity between what value to be considered among the those 2 values. If you can attach an example form if not the original form for reference it would be helpful.

Thanks and Regards,