How to use "if" and "then" on survey 123?

8467
9
05-09-2018 05:09 AM
Marcos_AntonioLima_Rios
New Contributor II

Hi, guys. First of all sorry for my poor english.

I need to know how to use "if" and "then" to set a value. 

For Exemple:

I have a fild that need to display a value to the user: 

   If (totalbrocasha "greater than" 3000 then coposliberar "equal" 12)   

9 Replies
IsmaelChivite
Esri Notable Contributor

The following expression will return 12 if totalbrocasha is greater than 3000 and otherwise, it will return 0.

if (${totalbrocasha}>3000,12,0)

You can use this expression in the calculation column of the coposliberar question.

The Quick reference—Survey123 for ArcGIS | ArcGIS is a great topic to learn all the things you can do with formulas in XLSForms.

Marcos_AntonioLima_Rios
New Contributor II

Nice, it's works. Thank you so much.

   I have one last doubt:

   And if I have more arguments?

   For exemple:

      if totalbrocasha <= 399 then coposliberar need to be 0

      if totalbrocasha >= 400 and <= 2999 then coposliberar need to be 8

      if totalbrocasha >= 3000 and <= 3999 then coposliberar need to be 12

      if totalbrocasha >= 4000 and <= 5999 then coposliberar need to be 18

      and finally if totalbrocasha >= 6000 then coposliberar need to be 22

0 Kudos
Marcos_AntonioLima_Rios
New Contributor II

I've tried this way: 

if(${totalbrocasha}>6000,22,if(${totalbrocasha}<=5999>=4000,16,if(${totalbrocasha}<=3999>=3000,12,if(${totalbrocasha}<=2999>=400,8,0))))

But the result is aways "0".

JoeBorgione
MVP Emeritus

Nested if statements are really tough sometimes.  These are a lot like what is used in attribute assistant:  All methods - Attribute Assistant | ArcGIS Solutions  (scroll down to additional functions).  I suggest working with your statements one at a time, adding as you go.  See:  https://community.esri.com/thread/183208-iif-function-in-dynamic-value-table 

That should just about do it....
Marcos_AntonioLima_Rios
New Contributor II

Thank you for your help, Joe.

I've tried the solution that works for IIF function in Dynamic Value table (using 0, Null, <Null>, 00, "", [#] and "Nothing", like Jennifer Stone did).

But I still receiving only 22 or 0 as a final result.

0 Kudos
JoeBorgione
MVP Emeritus

I wish I could provide more help but I'm just not that good with xls expressions.  That said, does you data coupled with your logic support any other results than 22 or 0?

That should just about do it....
Marcos_AntonioLima_Rios
New Contributor II

Thank you so much. I followed your advice:

"I suggest working with your statements one at a time, adding as you go."

And it works! I appreciate your help. 

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Marco,

Your evaluations for the if() functions after the first will not work - what you are trying to do would require a compound statement (i.e., ${totalbrocasha}<=5999 and ${totalbrocasha}>=4000 ).  That being said, with a nested structure like this, you don't need one side of the limit - it's already taken care of by the previous statement (i.e., the <=5999 is unnecessary as you already have caught all values larger with the first evaluation >=6000 ).

Marcos_AntonioLima_Rios
New Contributor II

Thank you so much.

0 Kudos