Trigger calculations when coded domain selected by user

1371
9
Jump to solution
05-02-2017 03:57 PM
by Anonymous User
Not applicable

Hi all,

I am creating a form and have a field with the following coded values:

0     
1     Circular
2     Arch
3     Square
4     Open Square
5     Open Arch

Each of those coded values should have a calculation associated with it. for instance, if user selects "Circular" then survey123 would automatically trigger the following equation (knowing that we have some of the variables in other fields):

V=πr2h

Is it possible in survey 123?

Thanks,

Alex

0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Alex,

This would be placed in the calculation column and would actually be more like how Excel specifies this (nested evaluators):

if(${SW_TYPE_SHAPE} = "1", <function1>, if(${SW_TYPE_SHAPE} = "2", <function2>, ...))

View solution in original post

9 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Alex,

There are a couple of ways, depending on how you plan to store the results of the calculation.  If they can be in separate fields, you can make a question for each formula that has a relevant statement set to only present the question with the proper choice selected.  If they need to be stored in the same field, you would use a series of nested if() functions to check which value is selected and then execute the appropriate function.

by Anonymous User
Not applicable

I would rather have the second option in my form. Where would I plug in these nested if() in my form?  And would it be something like  (in python? in the follwing example I am using JS):

if (${SW_TYPE_SHAPE} = "codedvalue"){
code goes here
}
else if(${SW_TYPE_SHAPE} = "codedvalue"){
code goes here
}‍‍‍‍‍‍
0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Alex,

This would be placed in the calculation column and would actually be more like how Excel specifies this (nested evaluators):

if(${SW_TYPE_SHAPE} = "1", <function1>, if(${SW_TYPE_SHAPE} = "2", <function2>, ...))

by Anonymous User
Not applicable

It seems like Excel does not like the $ . What am I doing wrong here?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Don't use an equal sign (=) that is asking Excel to do the calculation, not Survey123.

by Anonymous User
Not applicable

One last thing. Sorry I am not familiar with this. I get that error

When entering the formula this way: if(${SW_TYPE_SHAPE} = "1", <function1>, if(${SW_TYPE_SHAPE} = "2", <function2>, ...))

It seems like it cannot navigate to the "choices" sheet. I am not too sure how to reference that SW_TYPE_SHAPE. 

Thanks,

Alex

0 Kudos
IsmaelChivite
Esri Notable Contributor

The string within the curly brackets references an existing question within your form. Simply put the NAME of the question in your form that holds the values for the shape type and you should be good. The error you are getting indicates that your formula is referencing a question named SW_TYPE_SHAPE, which is not present  in your XLSfile.  Please note that questions are referenced through the value  in the NAME column, not the LABEL.

These links show in more detail how to use formulas in Survey123

https://community.esri.com/groups/survey123/blog/2016/09/06/new-mathematical-functions-make-your-for... 

Formulas—Survey123 for ArcGIS | ArcGIS 

 The Calculations sample form is also a good reference to get started with expressions in Survey123. You can create a dummy form using this sample and then look at the XLSFile to learn the syntax

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Alex,

Without seeing your Excel sheet, I can't be certain.  The cropped image provided above does not have a question named SW_TYPE_SHAPE, and the labels don't distinguish which question is which.  What is the name of the question with values you are evaluating (I was simply copying from what you provided as an example)?

0 Kudos
by Anonymous User
Not applicable

Thanks Ismael for the good calculation samples you provided. That will be very useful.

James, Thank you for your help. I was not referencing the domain choice name not the actual form question. The issue is solved. I can now enter the formulas in nested IF statements. Great product by the way.

0 Kudos