Summary
In some cases, when analyzing different fields for the same features in an attribute table, it is necessary to identify matching values in two fields. A new field can be created and calculated to reflect the noted comparison between the two fields. This article provides the instructions to do so in ArcGIS Pro. In this example, the comparison is made between the SOURCE and SOURCE_ED fields. The matching values are identified and populated in the new field, SOURCE_MATCH.
Procedure
- Add a new field to the attribute table.
- In the table, click Add Field
. The Fields view opens. - In the Fields view, specify a name for the new field in the Field Name column. In this example, the new field is SOURCE_MATCH.
- Double-click the Alias column of the new field, and specify an alias for it. In this example, the alias is SOURCE_MATCH.
- Double-click the Data Type column of the new field, and select Text from the drop-down menu.
- On the top ribbon, on the Fields tab, click Save
.
- Calculate the new field to identify matching values in the two fields.
- Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
- In the Calculate Field window, for Input Table, select the table containing the fields to compare and the new field.
- For Field Name (Existing or New), select the new field created in Step 1. In this example, the field is SOURCE_MATCH.
- For Expression Type, select Python 3.
- Copy the following expression, and paste it in the Expression box. Replace !field1! and !field2! by double-clicking the two fields in the Fields list. In this example, the two fields are SOURCE and SOURCE_ED.
calc(!field1!,!field2!)
- Copy the following script, and paste it in the Code Block box:
def calc(field1 , field2):
if field1 == field2 :
return 'Yes'
else:
return 'No'
Replace field1 and field2 with the two fields to be compared. In this example, field1 and field2 are replaced with SOURCE and SOURCE_ED respectively.
def calc(SOURCE , SOURCE_ED):
if SOURCE == SOURCE_ED :
return 'Yes'
else:
return 'No'
- Click the Verify
icon to validate the expression. - Click Run.
The following image shows the new field containing the identified matching values from two existing fields in the attribute table.