Working with IF ELSE statements

Hi all,

Long-time since posting! Trying to figure something out with an eventual ODK deployment (founded on XLS).

Problem
We have a list of 150 countries in the 'choices' tab. Each are numbered 1-150.

On the survey, we have 50+ questions - starting with a question asking respondents to select their country.

However, we want to filter some of the questions out if - for example - the country of the respondent is from a higher-income group. Is there anyway to do this without having to create an IF statement that lists all 50+ lower-income countries?

App or server
Standard ODK setup, and will be running on Android (devices TBC).

Ideas explored
Having an additional question as to whether the country is high or low income, but this risks data-entry errors.

Demo form
I'll see if I can anonymise and share a form.

Any ideas gratefully received!

Thanks!

Calum

I think you should be able to use pulldata() and an external dataset to do this.

country_detail_lookup.xlsx (10.0 KB)
country-details.csv (51 Bytes)

survey

+----------------------+---------------+-------------------------------+----------+--------------------------------------------------------+------------------------------------------------------+
|         type         |     name      |             label             | required |                        relevant                        |                     calculation                      |
+----------------------+---------------+-------------------------------+----------+--------------------------------------------------------+------------------------------------------------------+
| select_one countries | country       | Select your country:          | yes      |                                                        |                                                      |
| calculate            | income-level  |                               |          |                                                        | pulldata('country-details','value','key',${country}) |
| calculate            | country-label |                               |          |                                                        | jr:choice-name(${country},'${country}')              |
| note                 | note-country  | You selected ${country-label} |          |                                                        |                                                      |
| note                 | note-income   | It is ${income-level}         |          |                                                        |                                                      |
| begin group          | group1        |                               |          | ${income-level}='group-a'                              |                                                      |
| note                 | note1         | Questions for Group A         |          |                                                        |                                                      |
| end group            |               |                               |          |                                                        |                                                      |
| begin group          | group2        |                               |          | ${income-level}="group-b" or ${income-level}="group-c" |                                                      |
| note                 | note2         | Questions for Group B or C    |          |                                                        |                                                      |
| end group            |               |                               |          |                                                        |                                                      |
+----------------------+---------------+-------------------------------+----------+--------------------------------------------------------+------------------------------------------------------+

choices

+-----------+------+--------------------------+
| list name | name |          label           |
+-----------+------+--------------------------+
| countries | CAN  | Canada                   |
| countries | MEX  | Mexico                   |
| countries | USA  | United States of America |
+-----------+------+--------------------------+

country-details.csv

+-----+---------+
| key |  value  |
+-----+---------+
| CAN | group-a |
| MEX | group-b |
| USA | group-c |
+-----+---------+

1 Like

Hi Dan,

This is perfect, thank you! I had totally forgotten about the pulldata function.

Thank you!

Calum

@danbjoseph, thanks again for your expertise on this.

Out of interest, is it possible to nest statements in the 'relevant' column when pulling data from an external CSV?

For example, against one of the questions we already have this filter (which isn't pulling from elsewhere, it's just filtering based on the response to a previous question):

${sector} = ‘1’ or ${sector} = ‘2’

How would I add this (which is pulling from the .csv file):

${income-level}="group-b" or ${income-level}="group-c"

Into the same cell?

for a single question i think the following should work:
(${sector} = '1' or ${sector} = '2') and (${income-level}='group-b' or ${income-level}='group-c')

or if the group has the income relevance on it, and then the question inside the group has the sector relevance, it should accomplish the same thing (anything inside the group has to match the income levels, and then that question also has to match the sectors)

1 Like

This is perfect, thank you!