"If" calculations for select_multiple questions

08-27-2019 09:35 AM
Occasional Contributor II


I am creating a survey using Survey123 Connect.  My current problem is that I'm trying to do "if" statements in the "calculation" field for a select_multiple question, and it is not working (it seems to break the functionality of various repeats and relevances in the survey, even ones that do not seem connected in any way to the calculation I'm talking about).

My main questions are:

1)  Is it even possible/supported to do "if" statements within select_multiple questions, for the purpose of automatically selecting one or more of the choices based on user's answer to a previous question?

2)  How do you write a calculation that includes 2 separate/independent "if"/conditional statements? 

Here is my draft of the "if" statement:

if(${minor_count} > 0, ‘MinorsPresent’,‘’) and if(${youth_count} > 0, ‘Youth18to24’, ‘’)


Earlier in the survey, the user can enter various people's dates of birth, within a repeat; these are people who are present at a homeless camp.  I have a calculation in the survey to convert the people's ages into decimal-date-time (by subtracting their DOB decimal date from the decimal date of now().), and then I calculate the number of minors (minor_count) and the number of youth ages 18-24 (youth_count).  If there are any minors and/or youth--that is, if minor_count or youth_count is greater than zero--then I want to select choices within the select_multiple question.  This select_multiple question includes choices for minors being present and youth being present.  If there are any minors, I want to select 'MinorsPresent.'  And if there are any youth, I want to select that youth are present.

Thank you in advance for any help!


0 Kudos
6 Replies
Occasional Contributor II

Since I haven't solved my problem yet, I'm going to get around it by turning my select_multiple question into a series of select_one questions - user will answer yes/no for each of the choices.  Then I can write a separate "if" statement for each of those questions.  It's not ideal, but it'll work.

If anyone is able to answer my original questions, I would still really like to hear from you!

0 Kudos
MVP Esteemed Contributor

You need to use selected(${Customers},'Other')

There are many posts about this - see here https://community.esri.com/thread/184917-relevant-field-syntax-for-multiple-choice-questions 

0 Kudos
Occasional Contributor II

Doug, thanks for your reply. 

However, the post you provided a link to does not actually relate to my question, as far as I can tell.  I'm working on what to type in the "calculate" field for a select_multiple question, in order to automatically select choices based on the user's answer to a previous question.  That other post is about using the "relevant" field to make a question hide or appear based on a user's answer to a previous question.

What I wanted to figure out is, what should the syntax of the "if" statement be for this kind of scenario:

If question 1 is "yes," then select choice A for question 5.

If question 2 is "yes," then select choice B for question 5.

If question 3 is "yes," then select choice C for question 5.

Any combination of A, B, and/or C can be made (because it's a select_multiple question).

Since "question 5" is obviously a single question with only one "calculate" field, I need to somehow put all 3 of those "if" statements into that one field.  This is what I don't know how to do.

0 Kudos
MVP Esteemed Contributor

Sorry I think I am not getting the logic then.  If you just want to calculate a value then a select multiple is not needed - just calc it.  Do not need a drop down if you are just calcing the answer.

I also do not like select multiple because it will store values as A,B,C in a list.  This makes it hard to use later.  But if you want it that way a calc that concatenates the 3 fields would work.  So minor has a calc of if(minor>0, "Present", "").  The last field is concat(minor, etc).  But data wise I would have 3 fields that are just Yes/No for each.  Must easier to symbolize and such.

I am also not sure why if you have a youth count field you need a present field.  If it is > 0 then present.  Seems like double data.

Sorry not sure I get it.

0 Kudos
New Contributor II

Hi Allen,

I'm trying to do a very similar thing - did you ever figure out how to nest the "if" statements to make this work?



0 Kudos
Occasional Contributor III

I know this thread is old, but someone may need this answer in the future.

I did something similar last week that might help.

if(selected(${Antibiotics}, 'Yes') or selected(${Radioactive}, 'Yes') or selected(${Biological}, 'Yes') or selected(${Other}, 'Yes'), 'Yes', 'No')

0 Kudos