How to set a condition based on the answer from a selected position in repeat group

Hi,

I would like to set a condition (relevance) based on the answer from the “selected” position in a repeated group.

I am designing a household survey that does the following.

(1) Collect household members’ names and roles (e.g., head, spouse, etc.) using “repeat”
(2) After the repeat ends, choose one name from the names entered in (1)
(3) Show a question ONLY IF the role of the selected name is NOT head.

I can do (1) and (2), but not sure how to do (3).

Suppose there are 3 members in the household as below.

  1. John Doe, head
  2. Mary Doe, spouse
  3. James Doe, child

Once I collect the information above using “repeat”, I ask who the respondent is

Q1. Select your name

  • John Doe
  • Marry Doe
  • James Doe

Then we ask Q2 ONLY IF John Doe (head) is NOT selected.

Q2. Met the household head yesterday?

  • Yes
  • No

Here’s how I programmed so far, but not sure what to write in “relevant” column in “select_one yesnow” row.

+------+-----------+------------+------------+
| type | name | label | relevant |
+------+-----------+------------+------------+
| begin_repeat | HH_roster | Household roster | |
| text | name| Name | |
| select_one role | role| Role in household | |
| end_repeat | HH_roster | Household roster | |
| select_one ${name} | name_resp | Select your name | |
| select_one yesno | meet_head | Met the household head yesterday? | |
+------+-----------+------------+

And “choices” sheet.

+------+-----------+------------+
| list_name | name | label |
+------+-----------+------------+
| role| head | Household head |
| role | spouse | Spouse |
| role | child| Child |
| role | other | Other |
| yesno| yes | Yes |
| yesno | no | No |
+------+-----------+------------+

How should I do (3)?

Any suggestions are appreciated.

Hi @DoubleD

You can use ${name_resp} != '' and ${HH_roster}[./name = ${name_resp}][position()=1]/role != 'head' expression in the relevant of the meet_head question. The first part of the expression ensures that name_resp is select and the second part gets the role of the selected member. We have to use [position()=1] to get the first member's role if there are multiple member with the same names, highly unlikely situation that a single household has members with duplicate name but quite possible or enumerator can make a typo. Without [position()=1], Central will not allow us to upload the Form.

1 Like

Thank you so much for your answer!