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?
Solved! Go to Solution.
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
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
I too am struggling with "if" statements. Here's my use case:
Thanks
A
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.
Hi Andrew,
btkinal_SyrUniv is correct- select_one questions will be calculable in 2.7.
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
Hi Andrew,
Your survey is working properly on the 2.7 version I am using - can you verify the version # you are using?
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')
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.
Survey123ConnectBETA 2.7.13 is all that is available on the Early Adopter site.