How use index-repeat()

Dear ODK Users,
I am facing a related situation.
I have a repeat group (details of household members) where one of the questions is age. As the form progresses, I have another group where I intend to capture information on the prevalence of WATSAN Among Under-five Children. Now I would like this second group only to show up only if in the household there is or are any children aged five years and below. Problem is, while the form seems to evaluate well in XLSForm Online, in ODK it gives an error (see attached). How can I solve this problem? I have read about Repeat Recipes and Tips, but still can't figure out what I need to do.
I have also attached a sample of the form for you to check out

impact_survey_household_questionnaire_2019.xlsx (30.2 KB) .

Thanks in advance

1 Like

Hi @Musinguzi_Polycarp

the error is in cell E24 of your excel file.
You are trying to refer a repeated variable ${Q201d}, and the application does not know which iteration you want to use. At the end of the error message you have a hint, which is to use the indexed-repeat() function.

In your particular case I'd suggest two possible approaches:
a) if the second group of questions "children-under-five" refer to the expenses of the whole household, you might want to create a calculated field after the repeated group to count the number of household members below 5. The relevant condition for your group "children-under-five" would then become that this variable is greater than zero;
b) if the second group contains questions that might be relevant to each of the children, you might want to take questions Q500a-Q502 and move them into the repeated group. In this case, you could use your existing relevant condition for each of the questions (because they will be inside the loop).

I hope this helps!

Best,
Andrea

1 Like

Thanks @Andrea_Martin for the tips. Option one is the most relevant in my case, but please advise on how the calculation would look like. Thanks

Any help how to get this calculation done? I have used count(${Q201d})<5, but it doesn't sem to give me the number of children in the family below the age of 5. Kindly assist

Hi @Musinguzi_Polycarp

Please find attached (impact_survey_household_questionnaire_2019_AM.xlsx (28.2 KB) ) an edited version of your form, that should address your problem.
The edits include:

  • adding a calculated field (${below5})
  • editing the relevant field to count how many children below (or equal to) 5yo are present in the household.

I hope this helps!

Best,
Andrea

2 Likes

Many thanks, @Andrea_Martin. One last thing, having asked the age of each household member in that repeat group, how then can calculate the number of children aged 5 and below as well as those above 5. Using if(${Q201d}<=5,1,0) only shows me that there are children aged 5 and below, but doesn't tell me how many. Similarly, count(${Q201d})<5 wasn't helping either

Hi @Musinguzi_Polycarp

To calculate the number of children below 5 you can do as per file I attached before.
There are different approaches, but the one I'm suggesting is:

  • You include in the repeat group a calculate variable "tagging" the observations you are interested in, for example the var ${below5} takes the value 1 if the age is <=5;
  • You create a calculate variable outside the repeat group summing up the values (counts) of the variables you have tagged - e.g. sum(${below5})
  • You can adapt this approach to other age brackets or variables.

Note that:

  • in the file I sent you

I skipped the creation of a new calculated variable and just included the formula in the relevant field

Best,
Andrea

1 Like

Thanks, @Andrea_Martin worked fine.

Hi, @Andrea_Martin
I am facing the same issue but not able to trace why this issue is coming. In my case, I am not referring to intergroup and not needed any value from other groups. Please attached the Excel form. The group "Survey" is absolutely working fine, however, as soon as I start group "relative" at row number 265 it suggests use the index-repeat function. Kindly help. ASPIRE_v20.1.xlsx (90.6 KB)

Hi @Naveen_Agarwal

I am not sure I understand which issue you are experiencing.
I tried to convert the your form with https://opendatakit.org/xlsform/ and it doesn't throw any errors. Kindly provide more details to better assist you (see below).

  1. What is the problem? Please be detailed.
  2. What ODK tool and version are you using? And on what device and operating system version?
  3. What steps can we take to reproduce the problem?
  4. What you have you tried to fix the problem?
  5. Anything else we should know or have? If you have a test form or screenshots or logs, attach here.

Best,
Andrea

Hi everyone
have this problem and I can't figure out the solution please can you help me?
20201210_Chemonics - Manahel Parents (Caregiver) Questionnaire.xls (213 KB)

Hi @mmusto
it looks like you are trying to refer to questions that are inside repeats being outside of such a group. Then you need to use indexed-repeat function to define which repeat you want to refer.
Your form is not small and you need to review it carefully on your own but you made that mistake at least in two places:

  • row 59 in relevant you have ${N_Pa_1_3_boys_son_go_school} ='1001' but ${N_Pa_1_3_boys_son_go_school} is a repeatable question so you need to specify the number of repetition you want to refer.
  • row 71 in relevant you have ${N_Pa_1_3_girls_daughter_go_school} ='1111' and the same mistake as above

if you don't understand how to fix your problem please read Referencing repeated questions from outside the repeat it should help.

1 Like

Hi Grzesiek2010....i have a problem with my indexed repeat: i am trying to ask follow-up question from previous repeat about children between the ages of 6 months to 24 months but i don't how to implement this...can you help me?

Hi @Charles_Marc
Please attach your form (or a short version of it if it's big) so that we can take a look at it and help you.

A post was split to a new topic: Error evaluating

kobo _support.xlsx (41.7 KB)


Hi Grzesiek,
I a having an error on my form and I dont know the source. I have attached a screen shot of the error and the xlsform.
Kindly assist me in finding my way around.

Thanks, Everyone, I was able to sort myself out. I realized that ${child_attend_school} was referenced outside the repeat group.

A post was split to a new topic: Option to repeat questions?

A post was split to a new topic: How to use index-repeat()

3 posts were split to a new topic: Error when trying index-repeat()