HOW TO

Use multiple conditions in a single IF statement in an Arcade expression

Last Published: May 19, 2022

Summary

In ArcGIS Online, multiple conditions in a single Arcade 'if else' statement are used to simplify tedious workflows that use multiple IF statements. The example below is a script with multiple IF statements.

if ($feature == 1)
{
    "odd"
}
else if ($feature == 2)
{
    "even"
}
else if ($feature == 3)
{
    "odd"
}
else if ($feature == 4)
{
    "even"
}
else if ($feature == 5)
{
    "odd"
}
else if ($feature == 6)
{
    "even"
}

Procedure

To simplify the process, use the logical OR operator (||) to insert multiple conditions in a single IF statement.

  1. In ArcGIS Online, on the My Content tab, on the Content page, click the hosted feature layer to open its item details page.
  2. On the item details page, click Data and select the layer. In this example, the Pointing layer is selected.
  3. Click the field name of the feature layer and select Calculate. In this example, the feature layer, trial, is used.
The item details page with the Calculate option
  1. In the Calculate Field window, click Arcade.
The Calculate Field window to select Arcade
  1. In the Arcade Calculator window, under Expression, insert the following expression and click OK.
if (($feature.Id==1) || ($feature.Id==3) || ($feature.Id==5) || ($feature.Id==7))
{
    "Odd"
}
else if (($feature.Id==2) || ($feature.Id==4) || ($feature.Id==6))
{
    "Even"
}
else
{
    "none"
}

The following image shows the trial field is populated according to the Arcade expression.

The ArcGIS Online window with the hosted feature layer showing the trial field populated

Article ID: 000027592

Software:
  • ArcGIS Online

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options