ArcGIS Blog

Data Management

ArcGIS Online

Create Custom Field Calculations Using Arcade Expressions

By Lisa Berry

Arcade expressions offer a flexible way to work with your GIS data on-the-fly. You can use them to map your data, label features, configure a popup, and so much more. Now, you can now also use Arcade to calculate new fields directly into your hosted feature layers in ArcGIS Online.

Why use Arcade to calculate fields?

The ability to calculate fields in ArcGIS Online has been possible with SQL, which is great for large or synced datasets. However, calculating with Arcade is easy to learn, allows for more flexibility than SQL, and utilizes geospatial capabilities.

Arcade has been a great way to manipulate your data on-the-fly in your maps for a while now. But in some cases, you might need the results to be more permanent. For example, if you want to filter, chart, analyze, or export the results of an arcade expression, you would need the values to be built into the data table. You also need field values for advanced mapping techniques such as predominance and relationship mapping. This is where calculating a field with Arcade will help your workflows thrive.

Arcade allows you to access feature geometry, store constants and variables, and provide access to attribute values. You can utilize Arcade and its wide functionality to calculate new data-driven values. For example:

  • Basic calculations (ex: calculating a percent)
  • Use functions (ex: absolute value, round, logical statements, etc)
  • Create an index or ratio (ex: land improvement layer)
  • Text manipulation (ex: hurricane labels)
  • Use geometry-based functions (ex: Population Density, buffer, how many things are within a distance of me)
  • Data cleanup (ex: fixing incorrect values or mis-typed field values)

How to Calculate New Fields with Arcade in ArcGIS Online:

1) To start, choose to add a new field, or choose the field you want to calculate values for. This can be done from either the table view in Map Viewer or from the Data tab from your item description page. Choose Calculate from the field options

Tip: Using Calculate on existing fields with either SQL or Arcade will overwrite the existing data values. If you are worried about losing your original data, create a new field and calculate to that field instead.

 

2) Choose the Arcade option

3) Write your arcade expression. This example uses the Area geometry function to calculate population density.

Tip: Try your arcade expression within smart mapping to test the expression results first. This also allows you to see how well the attribute looks on a map. To learn the basics of mapping with Arcade, visit this blog or this Story Map tutorial.

 

4) Test your expression. If the test value looks correct, click OK to calculate your new field values.

Need inspiration?

The example above showed how to use a basic geometry function. Here are a few other examples that show arcade expressions and functions being used to calculate fields.

 

With the data below, I wanted to compare the number of people with a high school level degree or less to the population with above a high school education. To use the predominance mapping tool, and to show the values within a chart, I needed to use Arcade to combine multiple fields into two fields:

In this next example, I needed to fix text values that were in all caps by using the text function, Proper. With this change, I can easily use the new value within popups and labeling:

This example, inspired by this blog, calculates the ratio of land value and the improved value as a ratio. The input fields are text, and converted into numbers. This example uses multiple conversion functions as well as variables. By creating a new field, this value now be used within additional analysis, and also will allow me to filter my map by different values:

Share this article

Subscribe
Notify of
11 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Josh Saad(@saadj)
July 8, 2020 10:32 am

This is awesome functionality, and exactly what I need. Unfortunately, it’s for a Damage Assessment app that I need to enable offline sync. Do you know if that’s ever going to be supported for Arcade expressions? Do you know if it would be possible to create a view for offline syncing, and enable calculations on the main feature service?

Hiroki Nozaki(@hiroki-nozaki_cdss)
August 6, 2020 1:35 pm

When calculating field with Arcade Code, is the field a static or if anything changes, does it update it also?
I assume that this is a static field and if anything change, I will have to recalculate the field.

Hiroki Nozaki(@hiroki-nozaki_cdss)
August 6, 2020 2:07 pm
Reply to  Lisa Berry

Thank you for the reply.

I am trying to symbolize a layer based on intersection and I do not own both layer.
I created a custom attribute expression and tried to use that “new” field for symbology.

My next method was custom build a symbology with arcade but “FeatureSetByName” is not supported.
Is there anyway to accomplish this? I tried using intersects but no success at this point.

Ahmadreza Maddi(@amohammadalimaddi_nycdot)
October 16, 2020 10:11 pm

Hello,
Great Article.

Bonnie Claridge(@bclaridgeblm-gov_blm_egis)
November 27, 2020 10:43 am

Hi Lisa- could you point me to a good resource for using Arcade expressions specifically in Field Maps? Thanks!

Anthony Von(@avonmoosci-kennewick-wa-us_kennewick)
September 14, 2022 4:53 pm

In attribute assistant how would I build an expression which would copy the parcel number attribute from our parcel layer over to the parcel number attribute on our address point layer when a new one is created? This would be based on the parcel that the point being created sits on.

Last edited 2 years ago by Anthony Von
Chris Hamilton(@chris-h)
March 2, 2023 2:51 pm

Great article Lisa. I’m interested on what approaches could be used for calculations in WAB where a user needs the percentage area overlap between two hosted layers? The first layer (project areas) is reasonably dynamic and users create or adjust polygons based on many subjective inputs. Once edits are saved, we need to know the % overlap with defined features in another layer (e.g. a certain vegetation class in the vegetation layer). Reading through this blog it sounds like using the Arcade intersection() function in a popup “could” work but I’m assuming this would be highly computationally expensive. Would there… Read more »