Survey 123 help!

835
6
Jump to solution
04-22-2022 09:44 AM
MeganWheat
New Contributor III

I am working on a form in survey 123 for hydrant flushing. I am trying to figure out a way to have a field autocalculcate based on the selection they make from a select one option. 

For example if a port size is 2 inches and the high pressure is 200 gallons per minute and the flush total time is 5 minutes I want it to populate the answer to avoid user error calculation. 

Calculation in an excel would be (5)(200) = 1,000 gpm. How can I do this in survey 123 the syntax is throwing me off. I am been trying to mess with the pulldata() function and have had zero luck. I have also tried if statements but it kept giving me errors and the error messages were not helpful.

If anyone has any examples or can help guide me to get closer to my end goal I would appreciate the help!

Thanks!

0 Kudos
1 Solution

Accepted Solutions
Katie_Clark
MVP Regular Contributor

Got it! Here's the syntax you want:


if(selected(${port_size},'2'),'200', if(selected(${port_size},'2.5'),'300', if(selected(${port_size},'4.5'),'750','N/A')))

 

And I'm including this image here to show a trick I use when writing nested statements. I used a text editor (notepad++ in this case) that has syntax highlighting to help me with the parentheses. Notice in the screenshot, the very last parentheses is red, and it shows that it matches up with the very first parentheses (also red). 

Katherine_Clark_0-1650651213206.png

 

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek

View solution in original post

6 Replies
Katie_Clark
MVP Regular Contributor

Hi Megan! There is documentation on all the survey syntax for formulas here

So, if all you want to do is multiply those two fields, it would be ${total_elapsed_time} * ${gmp}

(I assumed the gmp field is what you were using for gallons per minute?)

If there's something I'm not understanding about what you're trying to accomplish, please let me know and I'll try my best to help!

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
MeganWheat
New Contributor III

Hi Katherine,

 

For the gmp field I was trying to auto populate it so that on port size if 2 was selected the gmp would fill in with 200 gmp. But it is seeming to be more complicated than I thought or that I am thinking too deep into this haha. And thank you for the other calculation the syntax for survey 123 I am still trying to figure it out it is just different for me!

0 Kudos
Katie_Clark
MVP Regular Contributor

Well for an if-statement it would be:

if(selected(${port_size}, '2'), '200', 'N/A')

In this example, it's saying IF 2 is selected for "port size", assign a value of 200 for this field, ELSE IF 2 isn't selected, assign 'N/A'.

The key is to have a value for the IF TRUE and ELSE parts of the statement. You can make the if-statement check for multiple conditions, like IF 2, return 200. IF 1, return 150. If neither of those are true, then return X.

Here's one of my posts from several years ago where James Tedrick provided a very helpful answer regarding the syntax for nested if-statements. I still reference it when I write them!

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
MeganWheat
New Contributor III

Katherine,

I think most of my confusing comes from the nested if statements. 

This is what I have but I am getting an error, most of my confuse lies with having an statement to end it if the choices I have arent selected then nothing happens if that makes sense. 

This is what I have for that calculation and the error that came with it. I really want to understand where I am going wrong so I can truly understand this as I am building many more surveys

If(selected(${port_size}.'2'),'200' or (${port_size},'2.5'),'300' or (${port_size},'4.5'),'750','N/A')

 

Thank you!

 

0 Kudos
Katie_Clark
MVP Regular Contributor

Got it! Here's the syntax you want:


if(selected(${port_size},'2'),'200', if(selected(${port_size},'2.5'),'300', if(selected(${port_size},'4.5'),'750','N/A')))

 

And I'm including this image here to show a trick I use when writing nested statements. I used a text editor (notepad++ in this case) that has syntax highlighting to help me with the parentheses. Notice in the screenshot, the very last parentheses is red, and it shows that it matches up with the very first parentheses (also red). 

Katherine_Clark_0-1650651213206.png

 

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
MeganWheat
New Contributor III

Awesome! That is a great treat and I am going to use this to help me while working in survey 123! Thank you so much for all your help! I greatly appreciate it! 🙂

 

Megan