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

I am currently facing a challenge while designing a XLSForm 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:
|Column 1 | Column 2 | Column 3 | Column 4 | E|

line_no name sex marri age
1 JH 1 1 51
2 SY 2 1 47
3 HR 1 2 29
4 HE 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 XLSForm below), 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.”

type name label required calculation repeat_count read_only relevant
note person_list Please list the names of the people in your household.
begin_repeat person Member of household
calculate id yes position(…)
integer line_no Person’s Line Number in the Hoousehold yes ${id} yes
text name Firs Name yes
select_one sex sex Sex yes
select_one marri marri Are you married or not? yes
integer age Age yes
calculate eligible yes if((${sex}=‘2’ and ${age}>=15 and ${age}<=49 and ${marri}=‘1’), 1, 0)
calculate mwra yes sum(${eligible})
note eligible_note Total number of eligible women from the household for birth history questions is ${mwra}
begin_repeat womens Woman’s Detail yes ${mwra}
text wname Woman’s Name yes
integer rhid Eligible woman’s ID yes position(…) yes
integer rostno Women’s Line Number in the Household Roster yes indexed-repeat(${id}, ${person}, position(…)) yes
select_one yesno birth Have you ever given birth to a baby? yes
integer no_birth Number of total live birth. yes ${birth}=‘1’

I would greatly appreciate your assistance in resolving this issue and welcome any insights or suggestions to effectively implement this functionality in my XLSForm. Thank you for your help!

Welcome @Binaya41,
with the search function of this forum you can find previous related discussions and examples, please, Search results for 'eligible household members' - KoboToolbox Community Forum.

Please, also test the behaviour and for correct references when you move back from the 2nd repeat and add or delete cases or change referenced values in the 1st repeat.

Hint: Don’t forget, please, to always check your form with the Online validator, during development and before deployment.

The initial posting was duplicated in ODK forum. Fetching Line Numbers for Eligible Respondents from First to Second Repeat Instances - Support - ODK Forum. So, see discussion there too.

1 Like

@Binaya41, maybe this post discussed previously should help you solve your issue:

Thank you so much for the suggestion. The suggested post provided some insight but I am not able to resolve the issue. In contrast to the [select_random-female-eligible-respondent V1.xlsx](https://community.kobotoolbox.org/uploads/short-url/4ri0xcmRw8uOD1SRAjrQST3UaYR.xlsx), I am including all eligible women from the household. I store the position of eligible women in a variable outside the first repat. When I try to pass the position in second repeat, it does not work for me. In the second repeat, I want the ‘rostno’ field (please refer to XLSForm from my initial post) to capture the value of ‘line_no’ from the first repeat when the name of the women is entered in the ‘wnam’ field.