Is it possible to use an If Then Else statement in ArcGIS Online Label Expression

7492
2
Jump to solution
05-30-2017 10:22 AM
EugeneDurshpek
New Contributor III

I'm attempting to add the following expression to a layer in AGOL, but not able to make it work...

Here's what I have in ArcGIS Desktop which works...

Function FindLabel ( [InspectionOrigin], [ClockFromTrans], [ClockFrom] )

if ( [InspectionOrigin] <> "D") then
FindLabel = ( [ClockFromTrans] )

elseif ( [InspectionOrigin] <> "U") then

FindLabel = [ClockFrom]
end if

End Function

I'm attempting to recreate this in AGOL for one of my layers and am unable to get it to work.

I've tried multiple options, none seem to be successful.

Option 1

IIf($feature.InspectionOrigin = Text($feature.InspectionOrigin, 'U'), $feature["ClockFromTrans"], $feature["ClockFrom"])

Option 2

IIf($feature.InspectionOrigin = 'U'), $feature["ClockFromTrans"], $feature["ClockFrom"])

Option 3

IIf($feature.InspectionOrigin <> 'D'), $feature["ClockFromTrans"], $feature["ClockFrom"])

Any thoughts?

Thanks!

Eugene D.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

There are a couple way of doing this. First would be to use an If statement

if ( $feature.InspectionOrigin != "D") {
  $feature.ClockFromTrans
}
else if ( $feature.InspectionOrigin != "U") {
  $feature.ClockFrom
}‍‍‍‍‍‍‍‍‍‍‍‍

You can also use the logical function IIF

iif ($feature.InspectionOrigin != "D", $feature.ClockFromTrans, $feature.ClockFrom)‍‍

The documentation has more examples: ArcGIS Arcade | ArcGIS for Developers 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

There are a couple way of doing this. First would be to use an If statement

if ( $feature.InspectionOrigin != "D") {
  $feature.ClockFromTrans
}
else if ( $feature.InspectionOrigin != "U") {
  $feature.ClockFrom
}‍‍‍‍‍‍‍‍‍‍‍‍

You can also use the logical function IIF

iif ($feature.InspectionOrigin != "D", $feature.ClockFromTrans, $feature.ClockFrom)‍‍

The documentation has more examples: ArcGIS Arcade | ArcGIS for Developers 

EugeneDurshpek
New Contributor III

Thank you Ken. This was exactly what I was looking for. The first option (using the "if statement") worked well. I wasn't able to get the "iif statement" to label features successfully.

Again; thank you very much!

Eugene D.

0 Kudos