HOW TO
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.
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.
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"}
The Results field is populated with values based on the Grade1 and Grade2 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.
Get help from ArcGIS experts
Download the Esri Support App