Field calculations allow the hosted feature layer owner or organization administrator to alter the values of every row for a single field in the attribute table of a layer.
For example, if you have a hosted feature layer that stores information on property sales—including the sale price and tax rate for the property location—you could add a field to the layer to store estimated property taxes. To populate the estimated_property_taxes field, define a calculation expression for the field that takes the values in the sale_price field and multiplies them by the tax_rate values.
You have two options when writing calculation expressions on fields in a hosted feature layer:
- ArcGIS Arcade—Arcade is ideal for calculations that require more functionality than SQL, as Arcade provides access to attribute values and feature geometry, allowing you to create expressions that include spatial operations. Additionally, if an error occurs while calculating a particular row, you can stop and troubleshoot the problem, and start the calculation again after you correct the problem.
Note:
ArcGIS API for JavaScript 3.44 and later will not be updated with the latest ArcGIS Arcade language features. Arcade expressions authored in JavaScript API apps at version 3.44 or later will only support Arcade language features introduced in Arcade version 1.21 or earlier. To learn more about Arcade language support across ArcGIS products, see the Arcade version matrix.
- SQL—Use SQL for the fastest performance with calculations that can be performed with standardized SQL (SQL-92) expressions on nonspatial attributes. You can run SQL on sync-enabled hosted feature layers and layers configured to track feature creators and editors, whereas you cannot run Arcade expressions on such layers.
Follow these steps to calculate string, numeric, or date field values in a field from the table of a hosted feature layer or hosted table layer in Map Viewer.
Note:
Field calculations cannot be undone. For this reason, a good practice is to add a field, calculate values into it, and confirm the calculation is what you wanted. If it is, you can then calculate the original field to equal the added field. Once you confirm the values are correct in the original field, you can delete the field you added.- Confirm that you are signed in and, if you want to save your changes, that you have privileges to create, update, and delete content.
Note:
You can explore maps, add and configure layers, and more without signing in. To save your work, sign in before creating a map. - In Map Viewer, open the map containing the layer or add the layer directly.
- If you are working with a hosted feature layer, on the Contents (dark) toolbar, click Layers if the Layers pane is not open. If you are working with a hosted table layer, on the Contents (dark) toolbar, click Tables if the Tables pane is not open.
- In the Layers or Tables pane, click Options on the layer and click Show table to open the table.
- In the layer table, click Menu on the column containing the values you want to calculate, and click Calculate field.
The calculate field window appears.
- Choose the language to use for the calculation, either Arcade or SQL.
- Optionally, click Add new to add a filter to calculate values for only a portion of the data, and click Next.
Note:
If you do not add a filter, the calculation is run on all features. If you applied filters to the map or layers in the map before opening the calculate field window, these filters will not be recognized when calculating field values.
- Compose a calculation expression.
- For Arcade, use global variables, functions, and constants.
- For SQL, use basic operators, a field list, and functions.
Tip:
For examples of common calculations that can be performed in ArcGIS Online, see Example calculations.
- Optionally, do any of the following while composing an expression:
- Click Test features filter to add a filter to your test features.
Note:
This option allows you to filter your test features and does not impact what features will be calculated.
- Click Test features to view the table of your test features.
- Click Preview values to preview the calculated values for your test features.
- Turn the Auto preview toggle button off to prevent the calculated values preview from automatically updating while authoring an expression. Turn the Auto preview toggle button on to allow the calculated values preview to update while authoring an expression.
- Click Map , Table , or Map and table to navigate between views.
- Click Test features filter to add a filter to your test features.
- Click Run calculation to run the expression.
The time it takes for the calculation to complete depends on the expression's complexity and the number of features in your layer.