To learn more about Python expressions, see Calculate Field Python examples.
To learn more about Arcade expressions, see the ArcGIS Arcade guide.
To learn more about SQL expressions, see Calculate field values.
To learn more about VBScript expressions, see Calculate Field VBScript examples.
When used with a selected set of features, such as those created from a query using the Make Feature Layer or Select Layer By Attribute tool, this tool will only update the selected records.
Existing field values will be overwritten. Make a copy of the input table if you want to preserve the original values.
For Python calculations, field names must be enclosed in exclamation points (for example, !fieldname!).
For Arcade calculations, field names must be prefixed with $feature. (for example, $feature.fieldname).
To calculate strings to text or character fields, on the dialog box, the string must use double quotation marks (for example, "string"), or in scripting, the string using double quotation marks must also be enclosed in single quotation marks (for example, '"string"').
To calculate a field to be a numeric value, enter the numeric value in the Expression parameter with no quotation marks around the value.
You can create complex expressions using the Code Block parameter. Enter the code block either directly on the dialog box or as a string in scripting. The expression and code block are connected. The code block must relate back to the expression; the result of the code block must be passed to the expression.
The Code Block parameter is only supported for Python expressions.
You can use the Python math module and formatting in the Code Block parameter. You can also import additional modules. The math module provides number-theoretic and representation functions, power and logarithmic functions, trigonometric functions, angular conversion functions, hyperbolic functions, and mathematical constants. To learn more about the math module, see the Python help.
To calculate geometry information in Python, use Geometry object properties. For example, use an expression of !shape.pointCount! to calculate the number of vertices in a feature.
To calculate area and length in Python, use the getArea and getLength methods with a method and unit type.
- To calculate the geodesic area of polygons in square kilometers, use the following expression:
- To calculate the planar length of polylines (or polygons) in yards, use the following expression:
See the Polygon and Polyline objects for more information.
Learn more about geoprocessing tools and linear and areal units
When working with joined data, you can only update fields from the origin table. You cannot update fields from the joined table. To perform a calculation on the joined table, perform the calculation directly on that table.
Python expressions that attempt to concatenate string fields that include a null or divide by zero value will return null for that field value.
SQL expressions support faster calculations for feature services and enterprise geodatabases. Instead of performing calculations one feature or row at a time, a single request is sent to the server or database, resulting in faster calculations.
Only feature services and enterprise geodatabases support SQL expressions. For other formats, use Python or Arcade expressions.
Using the SQL option for the Expression Type parameter has the following limitations:
- The option is only supported for Db2, Oracle, PostgreSQL, SAP HANA, and SQL Server enterprise geodatabases.
- Calculating field values on joined tables is not supported.
- Versioned and archived enterprise geodatabase data is not supported.
- Undoing geoprocessing operations is not supported.
See your database vendor documentation for SQL expression help.