HOW TO

Populate a field based on values in other fields using ArcGIS Arcade in ArcGIS Online

Last Published: October 23, 2020

Summary

In ArcGIS Online, Field Calculator allows populating a field based on values from another field using the ArcGIS Arcade 'if' statement. Refer to ArcGIS Arcade: If statements and ArcGIS Arcade: IIf for more information. In some instances, a field must be populated based on the values of two or more fields. This article describes the steps to use multiple 'if' statements from ArcGIS Arcade to populate a field based on the values of multiple fields.

Procedure

In this article, the Grade1 and Grade2 fields contain the exam grades ‘A,’ ‘B,’ ‘C,’ or ‘D.’ The Results field is populated as ‘Excellent’ if both grades are ‘A', 'Good’ if one grade is ‘A’ and the other is ‘B’, ‘Satisfactory’ if both grades are ‘B’, or ‘Unsatisfactory’ if at least one grade is ‘C’.

Note:
The populated field type must be string, or the same as the other fields used in the expression.
  1. In ArcGIS Online, open the hosted feature layer attribute table from the item details page or in Map Viewer. Refer to ArcGIS Online: Show a table in Map Viewer for steps to do so.
  1. Click the header of the field to populate, and select Calculate.
Image showing the Calculate option when clicking the field header.
  1. Select Arcade in the Calculate Field dialog box.
Image showing the Arcade and SQL options in the Calculate Field dialog box.
  1. In the Expression box, type or paste the following Arcade expression, replacing field1, field1value, field2, and field2value with the desired field names and values.
if ($feature.field1 == "field1value" && $feature.field2 == "field2value") {return "outputvalue1"}
//Repeat the first line for all field1 and field2 values
else {return “outputvalue2”}

Replace outputvalue1 with the desired return value if the condition of the expression is met, and outputvalue2 with the value if the condition is not met.

The '&&' operator returns 'True' if both given conditions are true. For more information about operators in Arcade, refer to ArcGIS Arcade: Structure and Logic. In this example, the Results field returns ‘Excellent,’ ‘Good,’ ‘Satisfactory,’ or ‘Unsatisfactory’ based on the Grade1 and Grade2 field values, ‘A,’ ‘B,’ or ‘C’ using the following expression:

if ($feature.Grade1 == "A" && $feature.Grade2 == "A") {return "Excellent"}
if ($feature.Grade1 == "A" && $feature.Grade2 == "B") {return "Good"}
if ($feature.Grade1 == "B" && $feature.Grade2 == "A") {return "Good"}
if ($feature.Grade1 == "B" && $feature.Grade2 == "B") {return "Satisfactory"}
else {return "Unsatisfactory"}
Image showing multiple if statements for a field.
  1. Click Test to verify the expression, and click OK to run the expression.
Image showing the Test button to verify the expression and the OK button to apply the query in Arcade Calculator.

The Results field is populated with values based on the Grade1 and Grade2 fields.

Image showing the output field is populated based on the values of two fields.
Note:
The output field is not automatically updated when edits are made to the fields used for calculation, and must be recalculated using the same expression.

Article ID:000024112

Software:
  • ArcGIS Online

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic