Select to view content in your preferred language

If statement calculation, Survey123

39766
18
03-05-2018 10:57 AM
KatieWise
Emerging Contributor

I am working on creating form with multiple repeats/questions.  What I am trying to do is calculate an answer to a question based on the which answer was chosen from the previous select_one question.  I will use sample data for simplicity sake. 

select_one color: green, blue, red, yellow

calculation results based on color chosen (what I am trying): if(selected(${color}, 'red', 'Cardinal', if(selected(${color}, 'green', 'Parrot', if(selected(${color}, 'blue', 'Bluebird', if(selected(${color}, 'yellow', 'Finich', 'N/A'))))))))

I have received multiple different errors for trying this multiple ways, the current error is "requires 3 arguments, only provided 1"...Sometimes I get "requires 3 arguments, only provided 4 or 5 etc"

What am I doing incorrectly?

18 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Michael,

Just to check, how does the evaluation work when 2 of the variables would report one classification but one variable reports another?  For example, TP = 18, TN = 380, CholoroA = 3.1(1 Oligotrophic and 2 Mesotrophic)? 

For the most part, you calculation looks close to what your graph looks like; you shouldn't have commas in the evaluator section (for example, the first if should be ${P}<15 and ${TN}<400 and${ChloroA}<3 and I think your right-side parenthesis aren't lined up correctly - there should be 3 of them, one to close off each if() statement. 

0 Kudos
MichaelFazio2
Emerging Contributor

Thank you, James. To be honest, I hadn't considered the values being in two different categories at once. I'll have to ask the user. As far as the statement, I'm trying a nested if statement now, but just having trouble with my brackets and/or parenthesis

0 Kudos
GrzegorzIgnatowicz
Emerging Contributor

Hey folks!

According to this topic I have a problem with setting condition to auto-fill next question:

In select-one question named 'Assignee' I have few choices like 'James', 'Jessica', 'Adam'... and I want to set condition for next question named 'Assignee_Mail' to show me i.e. if 'Assignee' is James, 'Assignee_Mail' should be filled as 'james.smith@mail.com. This is very important for me because I want to use the question 'Assignee_Mail' field to set in Integromat as a dynamic value for e-mail recipient.

I tried few options for example...
if(selected(${Assignee}, 'James') or selected(${Assignee}, 'Jessica') or selected(${Assignee}, 'Adam'), ''jim@mail.com', ''jess@mail.com','adm@mail.com'))) but it doesn't work.

Could you help me please ?
Thank you in advance

G

0 Kudos
by Anonymous User
Not applicable

Hi Grzegorz,

Yes it is possible to do what you want, but you need to use nested if statements, not one if statement with or expressions. It should look something like this:

if(selected(${Assignee}, 'James'), 'jim@mail.com', if(selected(${Assignee}, 'Jessica'), 'jess@mail.com', if(selected(${Assignee}, 'Adam'), 'adm@mail.com', '')))

If that doesn't work, can you send a copy of your xslx file, and I can take a closer look and let you know the best way to do it.

Phil.

GrzegorzIgnatowicz
Emerging Contributor

Philip Wilson‌ I can't find words to thank you! I've been struggling with this query for few days. It works now!

G

by Anonymous User
Not applicable

I have found this thread useful so far but there is a hang-up somewhere (calculation, type etc) that is not allowing my calculation to go through...

Context: I'd like to collect water temperature data in both Fahrenheit or Celsius but I would like the form to convert any Fahrenheit calculations to Celsius so I can have one column (hidden on the survey) on my output .csv spreadsheet. Currently, I have a decimal 'temp' variable, a select_one 'unit' variable with 'fahrenheit' and 'celsius' and now im hoping for a hidden integer field to calculate celsius based on the select_one 'unit' and decimal 'temp' fields.

decimaltempWater Temperature
select_one unitunitTemperature Unit
decimaltemp_cCelsius

My current calculation "works"t and updates with my survey123 connect preview, however I do not get the Celsius field to populate on my preview form (currently leaving the field visible to test systems but eventually want it hidden).

if(selected(${unit},'fahrenheit'),int((${temp}-32)*0.55555),if(selected(${unit},'celsius'),int(${temp}*1),'NA'))

if unit is Fahrenheit

then int(${temp}-32*0.55555

else if unit is Celsius

then int(${temp}*1

else NA

Does my current calculation reflect that?

If I want a decimal output in my hidden calculation what relevant columns should I be utilizing? bind: type? bind:esriFieldType?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Clay,

Is there a third option, as you have nested the if statement to provide a value of 'NA' if neither Fahrenheit or Celsius is selected?  It does reflect what you describe, but doesn't make sense with the rest of your description.  If you want decimal output, 'NA' will not be a valid value.  You should set bind:Esri:fieldType to a floating point (Single/Double) field field type for decimal storage.

0 Kudos
JessicaJThompson
Frequent Contributor

Hello!  (Surveyt123 Connect | Version 3.14.274)

Thank you in advance for your assistance!!

I have an if/and calculation that creates a default value if 6 questions all have the same answer. However, one of the questions is relevant based on a previous response so it is is hidden on occasion, so it cannot be answered. This makes the if/and calculation void, even if all of the visible questions are have the same answer. 

Is it possible to solve this with the calculation? Or do I have to rethink the workflow?

 

Thank you!

Jessica

0 Kudos
ArchitSrivastava
Frequent Contributor

Hello All,

I am stuck with kind of a similar problem.

We have an external CSV from where want to verify the entered code. If the entered code is correct then show the rest of the questions and if the value entered in code is correct we want to provide suggestion saying that entered code is incorrect but the survey doesn't seem to try and meet the condition. We have the following if  statement

We pull the code value from CSV in a field name (code) as hidden and use the following calculation

if(selected('${code}'='${enter_security_code}','${code_check}') and selected(${code}!='${enter_security_code}'),'${check_the_code}','${code_check}')

 

But this seems to error out a below:

ArchitSrivastava_0-1693123220340.png

It would be great if I can get any suggestions as to why this is not working. Any help would be highly appreciated.

-Archit

0 Kudos