Note:
This tool is only available in ModelBuilder.
The Calculate Field tool uses an SQL expression to calculate values for a new or existing field. Overwriting a field for the output dataset will not impact the field values in the input dataset.
The output is an output data variable that can be configured as an intermediate layer or a hosted layer.
Examples
Example uses of this tool include the following:
- A dataset includes fields for the number of residential buildings with rooftop solar panels and the total number of residential buildings per neighborhood. Calculate Field can be used to create a new field and calculate the rate of solar uptake in each neighborhood.
- A dataset includes a number field where -9999 was used as a placeholder value, which would impact analysis results if this field was used as an input. Calculate Field can be used to change the field value to an appropriate default value for the subset of records with the -9999 placeholder.
Usage notes
Calculate Field includes configurations for the input, field calculation, and result layer.
Input
The Input group includes the following parameters:
- Input dataset specifies whether the input is a hosted feature layer or a hosted table layer. You can choose a dataset by clicking Layer
. Only apply calculations to certain records defines the criteria that determines which subset of records will have the field calculation applied. Those features that satisfy all criteria will be included in the subset. To define a query, click Build new query. An input dataset must be specified to edit the expression.
To apply the calculation to all records, leave this parameter blank.
Learn more about building a query
Field calculation
The Field calculation group includes the following parameters:
Field to calculate specifies the field in which the calculated values will be added. You can choose from a list of existing fields or create a new field.
If an existing field is chosen, any values currently within the field will be overwritten.
To create a new field, click Create new field and provide the following:Note:
Calculate Field creates a new output dataset. Overwriting a field for the output dataset will not impact the field values in the input dataset.
- Field name—Type a name for the new field. The field name cannot be the same as an existing field name in the layer, cannot contain special characters or spaces, and cannot be an SQL keyword.
- Field type—Select a field type from the menu. The field type will determine which data types and expressions are supported for calculating the field. The following field types are supported:
- Double—Numbers with decimal places.
- Integer—Whole numbers from -2,147,483,648 to 2,147,483,647 (long integer).
- Big Integer—Whole numbers from -9,007,199,254,740,991 to 9,007,199,254,740,991. Use this type when you need to store numbers that don't fit in the range of the integer data type.
- String—Any sequence of characters.
- Date—Date and time.
- Date Only—Stores a date but no time values. This is useful when times aren't needed, such as when recording the day a permit expires.
- Time Only—Stores a time but no date values. The time format is determined by your user settings. This field data type is useful for recording such values as departure time.
Field calculation expression defines an SQL expression used to calculate values for Field to calculate. Click Expression
to open the SQL expression editor window. Within the SQL expression editor window, use Fields
, Functions
, and basic operators to create a valid expression.Learn more about writing SQL expressions
If the output of the expression and the field type are partially compatible (for example, double and integer field types both support number outputs, but with different restrictions) the values will be automatically transformed to meet the requirements of the field type. The transformation will take place automatically and without any notifications.
The following table describes how certain outputs will be transformed to match the field type:Output Field type Transformation Double
Integer
Round to the nearest whole number
Date Only
Date
Append 12:00 a.m. UTC to each date
Date
Date Only
Convert the date and time to UTC and store the date
Date
Time Only
Convert the date and time to UTC and store the time
Result layer
The Result layer group includes the following parameters:
- Result type specifies whether the output is an intermediate layer or a hosted feature layer. The following options are available:
- Create intermediate data creates a temporary dataset that can be used as an input to another tool element. This is the default for all tools in a model.
- Create hosted layer creates a new hosted layer for the output dataset. If this option is chosen, the following parameters are available:
- Output name specifies the name of the layer that is created and displayed. The name must be unique. If a layer with the same name already exists in your organization, the tool will fail and you will be prompted to use a different name.
- If a layer exists with the same name, automatically overwrite it determines whether the model can be rerun without changing the name for the output layer. If the layer does not already exist in the organization, a new layer will be created on the first run of the model and will be overwritten in subsequent model runs. The parameter is enabled by default.
- Save in folder specifies the name of a folder in My content where the result will be saved.
- Overwrite existing layer specifies an existing hosted layer that will be overwritten by the tool output. If this option is chosen, the Layer to overwrite parameter is also available to browse to an existing layer.
Limitations
The following limitations apply to the tool:
- Calculate Field is only available in ModelBuilder. If you are not using ModelBuilder, you can calculate field values in Map Viewer.
- Spatial expressions are not supported.
- Lists of field values are not available in the query builder when the input layer or table is an output from another tool.
- If a calculated value for a string or number field exceeds the field length limits, the output will appear null for new fields or maintain the input field value for existing fields.
- Field calculations using incompatible input and output fields may produce unexpected results. For example, using a Time Only field to calculate a Date Only output will result in the date 1899-12-30 for all fields. Other incompatible field combinations include Time Only inputs with Date outputs and Date Only inputs with Time Only outputs.
Environments
This tool does not honor analysis environments.
Credits
This tool does not consume credits.
Outputs
Calculate Field creates an output data variable that may be intermediate or hosted data. The output dataset has the same geometry and fields as the input dataset, unless a new field is added for the calculation.
Note:
Calculate Field creates a new output dataset. Overwriting a field for the output dataset will not impact the field values in the input dataset.
Licensing requirements
This tool requires the following user type and configurations:
- Professional or Professional Plus user type
- Publisher, Facilitator, or Administrator role, or an equivalent custom role
Resources
Use the following resources to learn more:
- How to build a query
- Calculate field values (Map Viewer)
- Calculate field in ArcGIS Data Pipelines
- Calculate Field in ArcGIS Pro