Fetching Line Numbers for Eligible Respondents from First to Second Repeat Instances

I am currently facing a challenge while designing an ODK questionnaire for a household survey that involves two repeat instances. The first repeat instance focuses on creating a household roster to collect information about all family members. The second repeat instance is specifically designed for eligible women (i.e., married women aged 15 to 49) from the household, aiming to gather their birth history.

In the second repeat instance, my objective is to fetch the line number of married females from the household roster and store it in the second repeat instance. For example, consider the following data entered in the first repeat instance:

line_no name sex marri age
1 JH 1 1 51
2 SY 2 1 47
3 HR 1 2 29
4 HN 2 2 20
5 DV 1 1 27
6 EB 2 1 25

From this data, I want to target married females aged 15 to 49 for the second repeat instance. In this example, only line_no 2 (SY) and 6 (EB) are eligible for the second repeat.

I have attempted to use the position() function (please see cell E17 in the attached XLSForm), but unfortunately, I am not achieving the desired result. Specifically, when entering SY in "wname," I expect it to fetch 2 in the "rostno," and similarly, entering EB in "wname" should fetch 6 in "rostno."

I would greatly appreciate your assistance in resolving this issue and welcome any insights or suggestions to effectively implement this functionality in my ODK form. Thank you for your help!
Sample_form.xlsx (15.4 KB)

Ciao @Binaya_Chalise,

There could be more than one way to achieve the link between the two repeats. I edited your sample form with what I thought would be the least costly in terms of coding with below summary for reference

  • The two repeats to have the same repeat_count. This is because the second repeat would go through same number of iterations as the first one, only showing you the fields for eligible women (managed via `relevantly)

  • Add a group in the second repeat with a relevant linked to ${eligible} to wrap all questions with ease of managing visibility trough one relevant value

  • Add few read_only lines to recap the data from the previous repeat (i.e.: names, age, marital)

  • Set the relevant for second repeat to be visible only when there are eligible women ${mwra}>=1

  • The eligibility formula was modified as if(${sex}='2' and ${marri}='1' and (${age}>=15 or ${age}<=49) , 1, 0)

This method would allow you to retrieve data using indexed-repeat() with mirrored positions across the two repeats without any addition codes/functions (regardless of eligibility). It’s good that you are keeping the row_ids, this is useful for linking the repeats’ data later in a query or other lookup techniques.

I tested the solution, and it worked for me, hoping it works for you too. See the revised form: Sample_form copy.xlsx (16.6 KB)

Best regards,
Jules R

1 Like

Why posting twice, directly in parallel here and in the Kobo forum, see https://community.kobotoolbox.org/t/fetching-line-numbers-for-eligible-respondent-from-first-to-second-repeat-instances/49261 ? At least, providing a link to the public would be nice.


I think using relevance to hide non-eligible members as @jules_rugwiro is the ideal way to go. That way if the form user changes members entered in the first repeat, the second repeat is correctly updated. If instead you build the second repeat around eligible members only, edits to the first repeat can result in really bad data corruption (e.g. the answers submitted as about PersonA were actually given for PersonB).

I believe this may not work quite as desired in Enketo web forms, though, so do make sure to check that if you plan to make submission edits or use web forms for initial data collection.

1 Like