The ArcGIS Pro Calculate Field tool (also known as the Field Calculator) is used to mass populate attribute values for a field in a spatial or standalone table. If there are selected records in the table, the attribute value will be applied only to the selected records. Otherwise, the attribute change will be applied to all records in the table. The Field Calculator also includes the ability to undo operations.
In this tutorial you’ll learn how to use the Calculate Field geoprocessing tool to define attribute values. We’ll be using the Delinquent Parcels layer symbolized in red in the screenshot below.
In the ArcGIS Pro Contents pane right click the Delinquent Parcels layer and select Attribute Table. This will display the attribute table as seen below. When a table is displayed in ArcGIS Pro it is termed Table View.
There is another way to open the attribute table for a feature class. Click the Delinquent Parcels layer in the Contents pane to initiate the Feature Layer context menu. Then, select Data | Attribute Table as seen in the screenshot below.
For this example we’ll select 26 features from the Delinquent Parcels layer using the interactive Select by Rectangle tool found on the Map tab. The selection set was created to illustrate how the Calculate Field tool will operate on a selection set if one exists. The two screenshot below illustrate drawing the rectangle and the resulting selection set.
A ValAcre field (numeric) has also been added to the Delinquent Parcels layer. This field presently contains null values, but will be populated with an expression that calculates the value per acre for each parcel.
To initiate the Calculate Field tool open the Attribute Table for the Delinquent Parcels layer and either click the Calculate button in the Table View or scroll to the ValAcre field, right click the field, and select Calculate Field.
The Calculate Field tool is populated with the parameters seen in the screenshot below. The ValAcrea field has a field alias called Value Per Acre. We’re going to use Python 3 as the expression type (Arcade is the alternative). The Calculate Field tool also includes a Field section that contains each of the field associated with the selected Input Table. The Helpers section contains functions from the Python (or Arcade) language that can be used to perform various operations as part of the expression that will be created. The items in the Fields and Helpers section can be double clicked to add content to the expression below.
To populate the ValAcre field we want to divide the values from the land_value field by the values in the ACRES field. To achieve this we double click the land_value field from the Fields section, add the division operator (/) and then double click the ACRES field from the Fields section. The result is the following expression:
!land_value! / !ACRES!
The exclamation characters are Python syntax that is added to the expression. The same expression written in Arcade would be as follows:
$feature.land_value / $feature.ACRES
Notice that we have also clicked the Enable Undo toggle button. The Enable Undo toggle button will allow you to undo the attribute value changes created by the Calculate Field tool. If Enable Undo is not toggled on, any attribute expressions that are applied will become permanent immediately.
Click the Apply button to run the tool and populate the selected row values. Because a selection set has been applied to the Delinquent Parcels layer the result of the expression will only be applied to the selected records. You may need to click the Show selected records button to see the result.
If you switch back to viewing all records (Show all records button) you’ll see that any records that are not part of the selection set still contain Null values.
Since the Enable Undo button has been enabled the Calculate Field tool will include some additional tools at the top of the tool that will allow you to Undo, Redo, Save Edits or Discard Edits.
Click the Undo button to see the result. The values for the selected records for the Value Per Acre field should now be set to Null.
If you clear the selected set and repeat the above process the expression will be applied to all records in the table.