Conditional (if) Statement Documentation

7473
16
Jump to solution
05-11-2017 07:11 AM
BrentKinal1
Occasional Contributor III

I can't seem to find any good documentation on using if() statement in Survey 123,  I am fine with a creating a simple conditional statement but I'm having troubles with more complex conditional statements. If anyone has a link to some good documentation on using conditional statements in S123 please share.

I am trying to get at something like this:

if(selected${listA}), ''}) or if(selected${listA}), 'notlisted'}),'None', ${listA})

Basically I want to display this contents from "listA" in a note unless it's blank or the option "notlisted" was selected, otherwise I want the note to read "None"

Also wondering if there is a way to have a "not equal to" in an if() statement?

0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Brent,

The if statement works in the same manner as in Excel - to create complex statements, they need to be nested.  Based on what you're trying to accomplish, this should be the function:

if(count-selected(${listA}) = 0, 'None', if(selected(${listA}, 'notlisted'), 'None', ${listA}))

count-selected gives us the 'unselected' case (0 choices selected).  Note the paranthesis for selected- it's a function and needs to specify it's parameters.  This also assumes your question is called listA

View solution in original post

16 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Brent,

The if statement works in the same manner as in Excel - to create complex statements, they need to be nested.  Based on what you're trying to accomplish, this should be the function:

if(count-selected(${listA}) = 0, 'None', if(selected(${listA}, 'notlisted'), 'None', ${listA}))

count-selected gives us the 'unselected' case (0 choices selected).  Note the paranthesis for selected- it's a function and needs to specify it's parameters.  This also assumes your question is called listA

AndrewHargreaves2
Occasional Contributor III

James Tedrick

I too am struggling with "if" statements. Here's my use case:

  • Select_one {Asset} (this has choices of 'Residential Meter', 'Backflow Preventer' etc)
  • If {Asset} is set to 'Residential Meter' I wish to populate a second select_one question named {Enclosure} with the answer 'meter box'
  • Furthermore, if {Asset} is 'Backflow Preventer' I wish to set {enclosure} to 'vault'

Thanks

A

0 Kudos
BrentKinal1
Occasional Contributor III

Unfortunately I don't think you can do a calculate on a select_one question in the current version of S123, I think it will be possible in the upcoming version. For future reference the statement would look something like this:

if(selected(${Asset}. 'Residential Meter'), 'meter box', if(selected(${Asset}, 'Backflow Preventer'), 'vault', ''))

Another option here would be to use a cascading select, this won't select the option base on the previous question, but will allow you to limit the choice for the enclosure filed based on the asset field response.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Andrew,

btkinal_SyrUniv‌ is correct- select_one questions will be calculable in 2.7.

AndrewHargreaves2
Occasional Contributor III

I downloaded the 2.7 BETA as James Tedrick suggested here and am using Brent Kinal expression but getting an nothing. I've included my survey and would be grateful if someone could help me out with getting this right.

Thanks

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Andrew,

Your survey is working properly on the 2.7 version I am using - can you verify the version # you are using?

0 Kudos
AndrewHargreaves2
Occasional Contributor III

Hi JTedrick-esristaff

I'm using 2.7.13 BETA as shown below. As I understand the below calculation if {obstruction} is set to 'CANNOT LOCATE' then {surface_cover} should be calc'd to 'UNKNOWN' automatically. However, I just get nothing:

if(selected(${obstructions}, 'CANNOT_LOCATE'), 'UNKNOWN','LAWN')

S123 2.7

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Andrew, 

2.7.13 is a version to early to test this functionality.  You should be able to download Survey123 Connect 2.7.68, Survey123 field app 2.7.93 from the Early Adopter Community.

0 Kudos
AndrewHargreaves2
Occasional Contributor III

JTedrick-esristaff

Survey123ConnectBETA 2.7.13 is all that is available on the Early Adopter site.

0 Kudos