Difference between revisions of "SurveyCTO Conditional Filtering"

Jump to: navigation, search
m (Steven moved page Conditional Filtering to SurveyCTO Conditional Filtering: changed title to section standard)
(No difference)

Revision as of 09:24, 19 January 2018

Best Practice

Sometimes we want to restrict the available choices from dynamically populated choice lists. In this example we use a household roster, where we want follow up questions to only allow choices of Q1) males under 20, Q2) females over 20. The key is that we are able to ’increase’ the level of the fields from a repeat group up a level and combine everything there using the join() function.

This example builds upon the Dynamically Populated Choice Lists example by allowing us to focus on particular parameters during follow up questions.

There countless ways in which this can be applied in practice. More examples would be when preparing a choice list after a crop-level repeat group of crops that were irrigated and/or sold, or filtering household members who earn income. Remember that the filters can be applied to any parameter recorded inside the initial repeat group.

Coding Example

[LINK Here is a code example]. There are notes in the ’label’ column of calculate fields of the SurveyCTO explaining what each field does.

This is achieved through 3 steps:

  • Set up a calculate field inside the repeat group for each condition that you want to filter later (lines 17-20). The field should yield the repeat number is TRUE, blank if FALSE.
  • Add a set of joining calculate fields outside of the repeat group (lines 31-34). These result in a list of the repeat group calculate field results that adhere to the earlier condition, which are stored in select_multiple format, e.g. 1 4 5.
  • We then leverage this field by using it as the base for the filter in the questions on lines 35 and 36. Note the relevance fields only show these questions if at least 1 instance of the condition is TRUE.

Back to Parent

This article is part of the topic SurveyCTO Coding Practices