Using answers from a repeat loop to filter which answers can be selected in subsequent loops

Hello All,

I have a survey where we ask what crops a household grows, and then we ask
some follow up questions about each crop. The follow up questions are
structured in a repeat loop.

So that we know what crop each repeat loop refers to, the first question in
each loop is 'which crop will you ask about?'. Using the choice_filter
function they can select_one crop from the list of crops already given.

However, I would like to refine this further by removing options from
subsequent loops which have already been entered in previous loops. I am
almost there, as you can see in the attached file, using code along the
lines of:
"selected(${crops}, name) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, 1), name)) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, 2), name)) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, 3), name))"

But there is a problem! If I go back through the form to revise an
answer, and then skip forwards again through the loop iterations then the
option to select each crop disappears.

I have tried using indexing relative to the repeat loop position (see
below), but when using Collect I get an error saying I need to use the
index-repeat function.

"selected(${crops}, name) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, position(..)-1), name)) and
not(selected(indexed-repeat(${crop_name}, ${crop_repeat}, position(..)-2),
name)) and not(selected(indexed-repeat(${crop_name}, ${crop_repeat},
position(..)-3), name))"

Any ideas ???

Many thanks

Jim Hammond

Repeat_filter_example.xls (29.5 KB)

It is perhaps better to ask your respondents for the list of all of their
crops, then in the next repeat do not give them a choice of what crop they
are going to describe, but, instead, force them to answer questions about
the Nth crop identified within that first list. This avoids all the
cumbersome logic you are struggling with, though it does impose a strict
ordering for the second half of the interview.

Note, also, that the data collector SHOULD NOT go back and edit answers to
the first repeat group, as that would throw off all of the data collected
in the second loop. You might be able to add a confirmation screen listing
the crops identified in the first list and asking to "Acknowledge that all
crops have been identified", and once you've advanced through that screen
capture all of those crops in a field with a once() directive to ensure
that the list is never modified thereafter. And then use that list for the
second repeat where you ask questions about the Nth crop from that list.

Within your loop, the problem is your use of the ${crop_name} syntax to
refer to a field within a repeat group.

See: https://opendatakit.org/help/form-design/#xpath_expressions

You need to use relative references to the fields.

In general, what you are trying to do is very difficult within ODK Collect
because you want to limit the range to [1.. position(.)-1] when
constructing your constraints.

If you MUST allow the interviewee to select among the set of crops they
identified in the first list, and cannot impose an order on their
responses, the typical solution is to "unwind" your loop by assuming you'll
have no more than, e.g., 10 sets of crops.

Then make 10 copies of what was the body of your repeat group, and rename
the fields within from, e.g., 'crop_name' to 'crop_name1', 'crop_name2',
... 'crop_name10'.

Then you can do all the restrictive logic you want.

But this gets very, very, cumbersome.

ยทยทยท On Thu, Oct 20, 2016 at 5:35 AM, Jim Hammond wrote:

Hello All,

I have a survey where we ask what crops a household grows, and then we
ask some follow up questions about each crop. The follow up questions are
structured in a repeat loop.

So that we know what crop each repeat loop refers to, the first question
in each loop is 'which crop will you ask about?'. Using the choice_filter
function they can select_one crop from the list of crops already given.

However, I would like to refine this further by removing options from
subsequent loops which have already been entered in previous loops. I am
almost there, as you can see in the attached file, using code along the
lines of:
"selected(${crops}, name) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, 1), name)) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, 2), name)) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, 3), name))"

But there is a problem! If I go back through the form to revise an
answer, and then skip forwards again through the loop iterations then the
option to select each crop disappears.

I have tried using indexing relative to the repeat loop position (see
below), but when using Collect I get an error saying I need to use the
index-repeat function.

"selected(${crops}, name) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, position(..)-1), name)) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, position(..)-2), name)) and not(selected(indexed-repeat(${crop_name},
${crop_repeat}, position(..)-3), name))"

Any ideas ???

Many thanks

Jim Hammond

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com