Repeat a question only if specific question is selected for the person on the first position

1. What is the problem? Be very detailed.
I need to force the interviewer to introduce information about the household in the first position. Something like:

What are the relationship between the respondent and the household. for the first postition in the repeat the option selected must be "1-Household".

2. What app or server are you using and on what device and operating system? Include version numbers.
Samsung Tab 2016 and Android 10.

3. What you have you tried to fix the problem?
I tried to use calculation variable to get a boolean valeu (selected${variable}, '1-Household')

Hi @Ayod_El_Modai_Arune ,

To reference a variable inside a repeat group you might want to use the function indexed-repeat(), which allows you to specify the position (e.g iteration).

I hope this helps.

Best,
Andrea

Hi @Andrea_Martin,

Can you show me the syntax, please? I didn't understand well the syntax of index-repeat() function.
I didn't cache it well in the documentation.

Ayod

Hi @Ayod_El_Modai_Arune

The syntax is:
indexed-repeat(${question-name}, ${repeat-name}, index)

For example if you have a group ${roster}, and you are interested in the variable ${relation} for the first respondent (i.e. index==1), then you could create a calculate variable and in the calculation field enter:

indexed-repeat(${relation}, ${roster}, 1)

You can see another examples by searching similar questions in the forum, or at the link below in the Xlsx table, column calculate:

I hope this helps!

Best,
Andrea

Hi @Andrea_Martin,

I just got the variable, even the boolean result. Even so I don't know where to use this calculated variable. Please check this file https://drive.google.com/file/d/1V4xpcYHWk0aaeUTlxG8AlAxQIaeR_l92/view?usp=sharing in the row 26. I need to tell ODK: Don't repeat if "relacao_c_chefe" is 0.

Hi @Ayod_El_Modai_Arune

I think you have a couple of errors there:

  • the calculated field at row 26 cannot perform the operation because the variable ${s1p3} is yet to be computed.
  • also, the form supports entering more than one chefe

I would suggest a modification to the flow of your form.
A standard approach would be to collect information about the entire roster, starting from the chefe.
In this case you might want to skip question ${s1p3} for the first person and automatically assign the relation chefe. You could create an additional variable for this.
See example (_odkApp_iadcpc_AM.xlsx (117.3 KB) )
In the attached example I also pulled the name of the chefe from the top of the form, so you don't need to enter it again.

I hope this helps!

Best,
Andrea

1 Like

Thanks @Andrea_Martin.

Now I begin understanding better how this stuff (indexa-repeat function) works.

All the best!

1 Like

Glad to hear!

Good luck with your project @Ayod_El_Modai_Arune

Best,
Andrea