Stop question from appearing in repeat group after certain response

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 (85.4 KB)

Hi Seth,

you can find your solution on this forum post:

Look at the comment of LN on the indefinite-repeat XLSForm

2 Likes

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.

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 (31.5 KB)