HOW TO

Calculate a new field to identify matching values in two fields in an attribute table in ArcGIS Pro

Last Published: October 11, 2023

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

  1. Add a new field to the attribute table.
    1. In the table, click Add Field The Add Field icon to add a new field to the attribute table.. The Fields view opens.
    2. 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.
    3. Double-click the Alias column of the new field, and specify an alias for it. In this example, the alias is SOURCE_MATCH.
    4. Double-click the Data Type column of the new field, and select Text from the drop-down menu.
    5. On the top ribbon, on the Fields tab, click Save The Save button to save the newly created field in the attribute table..
  2. Calculate the new field to identify matching values in the two fields.
    1. Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
    2. In the Calculate Field window, for Input Table, select the table containing the fields to compare and the new field.
    3. For Field Name (Existing or New), select the new field created in Step 1. In this example, the field is SOURCE_MATCH.
    4. For Expression Type, select Python 3.
    5. 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!)
  1. 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' 
  1. Click the Verify The Verify icon to verfiy the expression in the Calculate Field before running the tool. icon to validate the expression.
  2. Click Run.
The Calculate Field window containing the parameters and expression to calculate the new field with matching values from two fields in the attribute table.

The following image shows the new field containing the identified matching values from two existing fields in the attribute table.

The attribute table containing the new field containing the matching values from the two fields.

Article ID: 000025230

Software:
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

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

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options