Description
In ArcGIS Pro, the Calculate Field tool fails to execute mathematical calculation on a field when the values contain the percent sign (%).
Cause
The values containing the percent sign, %, are stored in a text data type field. Mathematical calculation cannot be executed in a text data type field.
Solution or Workaround
To resolve this issue, populate a new numeric field with the values and remove the percent (%) sign. Use the Percentage number format on the numeric field to retain the percent sign in the values.
- Open the ArcGIS Pro project.
- Open the attribute table of the feature layer containing the text field with the percent values and sign.
- Create a new numeric field with the Percentage number format.
- In the attribute table, click Add to add a new field.
- In the Fields view, name the field and apply a numeric data type with the Percentage number format to the field. Refer to ArcGIS Pro: Format numeric and date fields for instructions. In this example, the test_field with the Double data type and the Percentage number format is created.
- Populate the new numeric field with data from the text field and remove the text with the percent (%) value using the Python rstrip() method.
- In the attribute table, right-click the field and select Calculate Field.
- In the Calculate Field pane, select Python 3 for the Expression Type parameter.
- In the Expression box, copy and insert the following code. Replace <my_text_field> with the text field containing the percent sign. In this example, the Rate field is used.
!<my_text_field>!.rstrip("%")
-
- Click Apply.
Demonstrated below is the populated numeric field in the attribute table. The values are numeric data types with the percent sign displayed and can be used for mathematical calculation.