English

How To: Display the sum of multiple attribute fields values from a related table in the ArcGIS Online pop-up

Summary

ArcGIS Online allows configuring a pop-up of a feature layer with a related table to display related data within the pop-up. However, to calculate and display the sum of multiple attribute fields values in the pop-up, some attribute expressions configurations must be done using Arcade. This article provides the workflow to calculate the sum of multiple attribute fields values in a related table of a feature layer using Arcade to be displayed in a pop-up.

Procedure

In this example, a hosted feature layer (PolygonParcel) is published in ArcGIS Online with a related table (Relate_19543). The feature layer and the table each have a field named 'FID_Tracts', and they are related based on this field. The image below shows the attribute table of the PolygonParcel feature layer. The related record is presented as a column with an italicized header on the right side of the attribute table.

An image of the feature layer attribute table.

The image below shows the attributes of the related table, Relate_19543. Value1, Value2, and Value3 are the fields containing the values to be summed up and displayed in the pop-up.

An image of the related table attributes.
  1. In ArcGIS Online, open the feature layer containing the related table in Map Viewer.
  2. Click the ellipsis An image of the ellipsis button. button of the layer and select Configure Pop-up.
  3. In the Configure Pop-up pane, configure the pop-up settings as desired. For more information, refer to Configure pop-ups.
  4. Under the Attribute Expressions section, click ADD to create a custom expression to calculate the sum of multiple attribute fields values from the related table.
  5. Optionally, click Edit to change the default Custom field name as desired, and click Save.
  6. In the Expression box, paste the following expression. Replace the variables in the angle brackets < > according to the data used.
var table = FeatureSetByName($datastore,"<name of related table>") //reads the related table into a variable
var total = 0 //define a variable for the sum

for (var t in table) {//loop the related table to find the related records for the feature
if (t.<the name of the field that the relate is based on> == $feature.<the name of the field that the relate is based on>) {
total = total + t.<field name 1> + t.<field name 2> + t.<field name 3>
}
}
return total
The image below shows the configured expressions based on the feature layer and related table mentioned above.
An image of the custom expression.
  1. Click OK to apply the expressions.
  2. Click OK in the Configure Pop-up pane.
  3. Click any feature in the map to display the pop-up. The calculated sum of multiple attribute fields values of the related table is displayed in the pop-up.
An image of the pop-up displaying the calculated sum of multiple attribute values from a related table.

Related Information