Select to view content in your preferred language

If Statement in a Calculation

628
3
02-09-2018 10:53 AM
KevinKozak
Occasional Contributor

Hello,

I have been trying to use a if statement in a calculation based upon the value of a different question. I can't find the answer by browsing topics so could use some help.

I have an alignment code with is an integer within a select one question. If the alignment code is 9 (N/A) then the approach condition should also equal 9 (N/A). The approach condition is also an integer. I have tried the following in the calculation column.

if(selected(${alignment_cd},9),9)

If(${alignment_cd}=9, 9)

However, the approach condition is not getting set. It seems straight forward but I cannot get it to work.

Thank you,

Kevin

0 Kudos
3 Replies
BrandonArmstrong
Esri Regular Contributor

Hi Kevin,

I believe that you want to include an additional variable to the end of your formula.  So, for instance, if the alignment_cd = 9 then give me 9, otherwise give me 'x'.  Something like this...

 

if(${alignment_cd}=9,9,0)

This is also outlined in the 'Formulas' section of the documentation linked below...

Quick reference—Survey123 for ArcGIS | ArcGIS 

Please let me know if this works for you.

Brandon

0 Kudos
IsmaelChivite
Esri Notable Contributor

I agree with Brandon Armstrong‌. The syntax of your if statement is incomplete.  See example below:

  • if(selected(${alignment_cd},9),9,0)    If option 9 in the 'alignment_cd' select_one or select_multiple question is selected, then the expression returns 9, otherwise it returns 0
  • if(${alignment_cd}=9,9,0)    The expression does the same thing, except that the 'alignment_cd' question does not necessarily has to be a select.

If your calculation is set on a select_one question, you will not see the value being set. This is because select_one questions do not support calculations as of 2.6.

Support for calculations on select_one questions will start with version 2.7.

0 Kudos
KevinKozak
Occasional Contributor

Hello Brandon and Ismael,

 

Thank you for your replies. I had missed the documentation of calculations not working select one questions, which is my situation. Also, I will include the else portion of the if statement next time.

 

Thank you,

 

Kevin

0 Kudos