Select to view content in your preferred language

Nested if/selection statements not working

2059
6
Jump to solution
02-16-2021 12:09 PM
MeghanJones
Occasional Contributor

Hello! I am creating a conditional calculation for an integer field based on selection/input in a different field.  To me, this seemed like a simple nested if statement, so please help me fix where I am going wrong with the logic or formatting. 

I've attached a word doc with all of the different attempts, but below is the last one I tried, selection options '2'-'6' are domain values for the field name ObstructionImpacted

(if(selected(${ObstructionImpacted},’2’),5div10), if(selected(${ObstructionImpacted},’3’),2div10), if(selected(${ObstructionImpacted},’4’),4div10), if(selected(${ObstructionImpacted},’5’),1div10), if(selected(${ObstructionImpacted},’6’),1),0)

So basically the logic I am trying to calculate is:

IF {ObstructionImpacted} = '2' then calculate 5/10 

IF {ObstructionImpacted} = '3' then calculate 2/10 

IF {ObstructionImpacted} = '4' then calculate 4/10 

IF {ObstructionImpacted} = '5' then calculate 1/10 

IF {ObstructionImpacted} = '3' then the result is 1

OR the result is 0

 

Any help would be greatly appreciated! @JamesTedrick    

 

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

Each has it own errors.  Try this one with some spaces missing.  Also all the parens all go at the end.

(if(selected(${ObstructionImpacted}, ’2’), 5 div 10, if(selected(${ObstructionImpacted}, ’3’), 2 div 10, if(selected(${ObstructionImpacted}, ’4’), 4 div 10, if(selected(${ObstructionImpacted}, ’5’), 1 div 10, if(selected(${ObstructionImpacted}, ’6’), 1 , 0)))))

Hope that does it

View solution in original post

6 Replies
DougBrowning
MVP Esteemed Contributor

Each has it own errors.  Try this one with some spaces missing.  Also all the parens all go at the end.

(if(selected(${ObstructionImpacted}, ’2’), 5 div 10, if(selected(${ObstructionImpacted}, ’3’), 2 div 10, if(selected(${ObstructionImpacted}, ’4’), 4 div 10, if(selected(${ObstructionImpacted}, ’5’), 1 div 10, if(selected(${ObstructionImpacted}, ’6’), 1 , 0)))))

Hope that does it

MeghanJones
Occasional Contributor

That did it! Thank you SO MUCH! This helps me write several more codes in my form as well; I really appreciate it. 

KaitlynAbrahamson
Regular Contributor

I'm having a similar issue with this kind of nested if statement.  I'm not sure if I am able to do a calculation like this with text instead of numbers. What I am trying to do is add a hidden field of "category."  I want some utilities labeled as Water, or Sanitary, or Storm all in one field.

Would someone look to see what I'm doing wrong, because I keep getting this automatic entry on the actual survey: ReferenceError: Water is not defined in expression.

(if(selected(${utility}, 'Hydrant'), Water Distribution, if(selected(${utility}, 'Gate Valve'), Water Distribution, if(selected(${utility}, 'Curb Stop'), Water Distribution, if(selected(${utility}, 'Sanitary Manhole'), Sanitary Sewer, if(selected(${utility}, 'Clean Out'), Sanitary Sewer, if(selected(${utility}, 'Storm Manhole'), Storm Drain, if(selected(${utility}, 'Inlets/Catch Basin'), Storm Drain, Other))))))))

Thank you!

0 Kudos
DeonLengton
Esri Contributor

Hi Kaitlyn

You just needed to put single quotes around the true parts of your if statement:

(if(selected(${utility}, 'Hydrant'), 'Water Distribution', if(selected(${utility}, 'Gate Valve'), 'Water Distribution', if(selected(${utility}, 'Curb Stop'), 'Water Distribution', if(selected(${utility}, 'Sanitary Manhole'), 'Sanitary Sewer', if(selected(${utility}, 'Clean Out'), 'Sanitary Sewer', if(selected(${utility}, 'Storm Manhole'), 'Storm Drain', if(selected(${utility}, 'Inlets/Catch Basin'), 'Storm Drain', 'Other'))))))))

It was complaining about 'water' not being a defined expression because it was the first string that wasnt quoted in single quotations.

Hope that helps. If there's still issues then please post your survey, it would make it easier to assist 

KaitlynAbrahamson
Regular Contributor

Thanks so much!  Worked like a charm!

0 Kudos
DougBrowning
MVP Esteemed Contributor

If it gets any bigger than this use pulldata to go get the category it will be easier.

0 Kudos