# Stop question from appearing in repeat group after certain response

**URL:** <https://forum.getodk.org/t/stop-question-from-appearing-in-repeat-group-after-certain-response/16327>\
**Category:** Support\
**Created:** [November 16, 2018, 6:33am UTC](https://forum.getodk.org/t/stop-question-from-appearing-in-repeat-group-after-certain-response/16327 "2018-11-16T06:33:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![caldwellst](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/caldwellst/32/10758_2.png) [@caldwellst](https://forum.getodk.org/u/caldwellst)\
**Post date:** [November 16, 2018, 6:33am UTC](https://forum.getodk.org/t/stop-question-from-appearing-in-repeat-group-after-certain-response/16327/1 "2018-11-16T06:33:55Z")

</div>

I have a repeat group asking questions about different household members. I want to ask for each member if they are the head of household. Is there a way to not ask this question once the respondent answer "yes" that a household member is the head?

I have tried to use calculates in a simple way:

```
calc_hoh calculating if(selected({hh_member_hoh}, "yes", "1", "0"))
calc_hoh_total calculating sum(${calc_hoh})

```

And then including in the relevant logic for hh\_member\_hoh

```
${calc_hoh_total} = 0

```

So now I'm breaking the parser since the relevant logic is referring to a calculate later in the form. I've tried including the calculates inside and outside the repeat group, and even putting the calc\_hoh\_total before the question hh\_member\_hoh but none works (as I would expect I guess).

Would appreciate if anyone had better ideas on how to do this that I haven't thought of. I've attached a reduced test form as an example. Thanks for the help!

[test.xlsx](https://getodk.b-cdn.net/uploads/default/original/2X/3/324bb3079235f8e276bfaa86546749319731b93b.xlsx) (85.4 KB)

---

<div class="post-metadata">

**Author:** ![aurdipas](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/aurdipas/32/1785_2.png) [@aurdipas](https://forum.getodk.org/u/aurdipas)\
**Post date:** [November 16, 2018, 7:09am UTC](https://forum.getodk.org/t/stop-question-from-appearing-in-repeat-group-after-certain-response/16327/2 "2018-11-16T07:09:23Z")

</div>

Hi Seth,

you can find your solution on this forum post:

> [@XLS form- Repeat select\_one question until "A" is selected](https://forum.getodk.org/t/xls-form-repeat-select-one-question-until-a-is-selected/15318/17):
>
> Hi @LN, In your indefinite-repeat XLSForm example, what the code should be if the END condition is "a" is selected or age \<50.

Look at the comment of LN on the [indefinite-repeat XLSForm](https://docs.google.com/spreadsheets/d/1Rs6N7_BQNA80LVHyyF8jtAQRtiVlmp75erstoyOYe38/edit#gid=0)

---

<div class="post-metadata">

**Author:** ![caldwellst](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/caldwellst/32/10758_2.png) [@caldwellst](https://forum.getodk.org/u/caldwellst)\
**Post date:** [November 16, 2018, 7:37am UTC](https://forum.getodk.org/t/stop-question-from-appearing-in-repeat-group-after-certain-response/16327/3 "2018-11-16T07:37:30Z")

</div>

Thanks Aurelio!

Sorry I didn't clarify in my post that the question I want this to apply to is part of a much larger repeat group, so don't want to stop the entire repeat based on this question. Looking at the previous posts from LN and trying to figure out how to apply that in this situation. My initial thoughts are to use that same code in a calculate, just need to work out how to stop the question if the specific response is ever answered (not just in the previous loop position). Any suggestions/help appreciated, or someone telling me I'm a fool and this will never work ha.

Will write back here if I am successful.

---

<div class="post-metadata">

**Author:** ![caldwellst](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/caldwellst/32/10758_2.png) [@caldwellst](https://forum.getodk.org/u/caldwellst)\
**Post date:** [November 16, 2018, 1:28pm UTC](https://forum.getodk.org/t/stop-question-from-appearing-in-repeat-group-after-certain-response/16327/4 "2018-11-16T13:28:03Z")

</div>

Update:

I feel that I've gotten close to a solution, but isn't working yet. Following the previous thread Aurelio referenced, I've implemented two calculates.

```
check_hoh = if(position(..) = 0 or /data/b1[position() = position(..) - 1]/hh_member_hoh != "yes"), 1, 0)
check_hoh_constant = if(${check_hoh} = 0 or /data/b1[position() = position(..) - 1]/check_hoh_constant = 0), 0, 1)

```

The idea was that check\_hoh will evaluate to 1 unless in the previous instance of the repeat group the respondent answered "yes" that member is the household head. Then check\_hoh\_constant will evaluate to 0 if check\_hoh is 0 this instance (meaning the response was "yes" in the previous instance) or if check\_hoh\_constant was 0 in the previous instance.

So, check\_hoh\_constant will always evaluate to 0 once "yes" has been selected. We can then use that as the relevant logic for the hh\_member\_hoh.

```
${check_hoh_constant} = 1

```

I thought this would work, but alas, it does not. In Enketo, the question never appears and in ODK Collect, the question always appears! I hope some of you could help me sort out what exactly the issue is. Isn't really that critical, as can just use a select\_one question later on to ask who's the household head, but it's quite fun trying to figure this out. I've attached the new test form below. Thanks!

[test.xlsx](https://getodk.b-cdn.net/uploads/default/original/2X/7/769e82c53729227d881c51cb12e3d1636dbfaa5b.xlsx) (31.5 KB)
