Select to view content in your preferred language

Sum on a related table field

137
2
12-03-2024 05:36 AM
Labels (3)
MathieuCain
Occasional Contributor

I have a feature layer in an ArcGIS Online map (could be point or a polygon) that has a one-many relationship with a table (previously established through a geodatabase upload). In the feature layer popup, I would like it to display the sum of the values in a single field in the related table (I've seen examples of Arcade expressions that sum the values of multiple fields in a single record, but I am interested in a more basic summary statistic of multiple records in a single field). I need this to be a dynamic calculation so that when records are updated in the related table, that sum will be updated as well. 

The follow-up question is how that calculated field will translate to the dashboard. Will it be treated as an actual field in the feature class layer (and have the zoom/pan map functionality if selected), or will it be treated as part of the related table (i.e., related tables in dashboard are not supported for zoom/pan in a map).   

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

You can use the FeatureSetByRelationshipName function to get the related records for your feature, then use the GroupBy function on that FeatureSet to get the sum of the values in a particular field. That would look something like this:

var relatedFeatures = FeatureSetByRelationshipName($feature, 'the relationship name', ['your field'], false)
var summary = GroupBy(relatedFeatures, '1', { name: 'Sum', expression: 'your field', statistic: 'Sum' });
return First(summary).Sum
0 Kudos
MathieuCain
Occasional Contributor

If I understand correctly, in the feature layer's pop-up, I add the following Arcade expression (the reason I ask is that I get a blank result every time): 

 

var relatedFeatures = FeatureSetByRelationshipName($feature, 'RelatedTableName', ['RelatedTableFieldName'], false)
var summary = GroupBy(relatedFeatures, '1', { name: 'Sum', expression: 'RelatedTableFieldName', statistic: 'Sum' });
return First(summary).Sum

 

0 Kudos