Calculated Expression in Field Maps to Sum Previous Records

05-01-2023 12:33 PM
New Contributor II

Hi, I have features with a related table and I am trying to write a calculated expression in Field Maps to calculate a field in the related table that I have added into my Smart Form called "CummulativeNoPhotos".

I'm trying to calculate a field with the sum the values from the field called "NumberPhotos" if the battery was not changed up until the last time the battery was changed. Otherwise I want the calculated field to be calculated to 0.  I have a field called "BatteriesChanged" in the related table to denote if the battery was changed and a field called "NumberPhotos" to keep track of the number of photos.

Curtently, it seems like it is summing all of the "NumberPhotos" in the entire related table not just the "NumberPhotos" for the specific feature of interest that I'm filling out a related record for. I am not sure on how to get the result I want.

So far I have this:

var record = Filter($featureset, "BatteriesChanged = 'Y'")
record = OrderBy(record, "Date")
if($feature.BatteriesChanged == "Y"){
return $feature.CummulativeNoOfPhotos = 0;
} else{

return Sum(record,"NumberPhotos");

0 Kudos
0 Replies