Select to view content in your preferred language

Conditional (if) Statement Documentation

8564
16
Jump to solution
05-11-2017 07:11 AM
BrentKinal1
Frequent Contributor

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
16 Replies
BrentKinal1
Frequent Contributor

Andrew, You should be able to find it here: Welcome to our Feedback Community 

AndrewHargreaves2
Deactivated User

Thanks JTedrick-esristaff‌ and btkinal_SyrUniv‌!!

0 Kudos
SteveRichards4
Emerging Contributor

I think you have your answer but for what it's worth I had some issues trying to implement nested if statements, they worked in excel but not in the Survey.

I actually found it useful for my brain (and to get it working) to break the problem down into separate 'calculate' lines, calculate is a special field type that does not display on the form it works just like a variable and can be used in the other calculations e.g

type,name,label,calculation

1/ calculate,dia_diff,Diameter Difference,${sec_6_log_dia_meas_len}-${sec_6_log_dia_disp_len}

2/ note,sec_6_log_dia_diff,Measured Difference (mm),if(${dia_diff}<0,${dia_diff} * -1,${dia_diff})

3/ calculate,dia_diff_score_low,Diameter Score < 400,if(${sec_6_log_dia_disp_len}<400,if(${sec_6_log_dia_diff}>25,0,3),3)

4/ calculate,dia_diff_score_high,Diameter Score >= 400,if(${sec_6_log_dia_disp_len}>=400,if(${sec_6_log_dia_diff}>50,0,3),3)

5/ integer,sec_6_log_score,Log Score,min(${len_diff_score},${dia_diff_score_low},${dia_diff_score_high})

The logic is:

1/ Calculate the difference between what is measured and what the machine displays

2/ Convert the measurement to an absolute value (ABV)

3/ If the log has a diameter under 400mm and the difference in measurement is >25mm this log scores a 0

4/ If the log has a diameter over 400mm and the difference in measurement is >50mm this log scores a 0

5/ The log score is the minimum of Length Score,Small Diameter Score or Large Diameter Score

I left out the log length score calculations but they are similar to diameter

I have attached the full survey if anyone wants to take a look - I have trimmed out a lot of the lookup data.

Steve

0 Kudos
deleted-user-jxpbpbjlZInj
Deactivated User

James Tedrick‌ ... can you help with an issue I'm having with conditionals? I'm trying to tell Survey123 to assign a value based on a response from a prior yes/no question. If yes, the field gets a value of 8. If no, then it needs to perform a calculation based on two other fields. I have:

if(selected(${Dead_Tree},'yes'),8, if(selected(${Dead_Tree},'no'),'(${Highest_Pot_Score})+(${Multiple_Defects_Score})'

but this isn't working. I've tried variations on this, but so far I haven't gotten it to work. Help! Please.

0 Kudos
by Anonymous User
Not applicable

Sunny, if you download NotePad++, then it will help you with making sure the brackets line up within this type of coding. When you place your cursor by a "(" it will then in return light up the corresponding ")" to help identify if the brackets are in alignment. I'd give Brent's answer a go...

0 Kudos
BrentKinal1
Frequent Contributor

Hi Sunny, Try this:

if(selected(${Dead_Tree},'yes'),8, number(${Highest_Pot_Score})+number(${Multiple_Defects_Score}))

0 Kudos
Carlos_AndresCamacho_Acuña
Frequent Contributor

Buenas tardes, 

es posible generar un tipo de condicional para que una pregunta de una encuesta desarrollada en survey Connect 123 permita diligenciar nuevamente el valor si a pesar de no cumplir con la condición el mismo dato se ingresa por segunda vez. ejemplo, un operario captura el dato de consumo promedio de agua, este valor debe validarse respecto al promedio de los últimos meses que se tiene como información base, si el valor ingresado es mayor al promedio, pida una verificación y se vuelva a diligenciar el valor, si en esta ocasión vuelve a ingresar el mismo valor, acepte el dato y llene el registro.

0 Kudos