Arcgis Pro Calculate field IIf arcade Or Python

480
3
07-20-2021 12:31 AM
Labels (1)
New Contributor II

I want to calculate a filed and struggle to understand how to code the expression.

``````var TrapType = \$feature.Trap_type;
IIf(TrapType = "Trapinator" or "Timms" or "Set & forget" , 'Possum', 'Rat');``````

What I would like:

If Trap_type=  "Trapinator" or "Timms" or "Set & forget"  --> Target_specie = 'Possum'
If Trap_type = other stuff --> Target_specie = 'Rat'

2 Solutions

Accepted Solutions
MVP Regular Contributor
``````// test for equal with ==
// Aracade doesn't have and/or/not, it uses &&/||/!
// test for equality has to be repeated

var TrapType = \$feature.Trap_type;
IIf(TrapType == "Trapinator" || TrapType ==  "Timms" || TrapType ==  "Set & forget" , 'Possum', 'Rat');

// easier:
IIF(Includes(['Trapinator', 'Timms', 'Set & forget'], TrapType), 'Possum', 'Rat');``````

Have a great day!
Johannes
MVP Regular Contributor
``````# same goes for python, except you can use and/or/not

TrapType = !TrapType!
return 'Possum' if TrapType == 'Trapinator' or TrapType ==  'Timms' or TrapType == 'Set & forget' else 'Rat'

# easier:
return 'Possum' if TrapType in ['Trapinator', 'Timms', 'Set & forget'] else 'Rat'``````

Have a great day!
Johannes
3 Replies
MVP Regular Contributor
``````// test for equal with ==
// Aracade doesn't have and/or/not, it uses &&/||/!
// test for equality has to be repeated

var TrapType = \$feature.Trap_type;
IIf(TrapType == "Trapinator" || TrapType ==  "Timms" || TrapType ==  "Set & forget" , 'Possum', 'Rat');

// easier:
IIF(Includes(['Trapinator', 'Timms', 'Set & forget'], TrapType), 'Possum', 'Rat');``````

Have a great day!
Johannes
MVP Regular Contributor
``````# same goes for python, except you can use and/or/not

TrapType = !TrapType!
return 'Possum' if TrapType == 'Trapinator' or TrapType ==  'Timms' or TrapType == 'Set & forget' else 'Rat'

# easier:
return 'Possum' if TrapType in ['Trapinator', 'Timms', 'Set & forget'] else 'Rat'``````

Have a great day!
Johannes
New Contributor II

Thank you soo much!

have a great day too

Lucile