Calculating Percent Difference
Included in this tutorial
Using the Calculate Field tool to calculate percent difference between values in two fields, with two examples.
Software version in examples: ArcGIS Pro 2.8.2
Tutorial Data: The tutorial includes demonstration with sample data available here.
Credits: L. Meisterlin with Moses Levich, Thiago Lee, and Erik Strand (2021).
This tutorial includes tips and examples for calculating the percent difference between values in two fields of an attribute table.
To calculate percent difference, you can build an expression within the Expression text box of the Calculate Field dialogue or define a simple formula with the code block. (For reference, see: Adding & Calculating Field Values in an Attribute Table.)
Example 1: Simple Expression
The percent difference between Field_A and Field_B (where “Field_B” includes your baseline values and “Field_A” includes your comparison values), can be calculated with the expression
( (!Field_A! - !Field_B!) / !Field_B!) *100
Note that you do not need to include a component that multiplies by 100, unless you want to convert the ratio values (which will be between -1 and +1) to percentage values (ranging from -100% to +100%).
Example 2: Expression + Code Block
Use the expression and code block below to return the percent difference between two numerical values.
Expression:
percentDiff(!Field_A!, !Field_B!)
Code Block:
def percentDiff(original, new):
return ((new-original)/original)*100
This example (below) demonstrates calculating the percent difference between values in the fields Int_lrg and Int_sm. To do this, we…
Choose Tracts_wTable under Input Table.
Choose an existing, empty numerical field under Field Name, in this case NewDbl, an empty field with Double data type.
For the Expression Type, ensure Python 3 is selected
Copy and paste the expression and code block, replacing Field_A and Field_B with Int_lrg and Int_sm in the Expression box.