Select to view content in your preferred language

Can I SUM an Arcade Expression Field?

1225
6
06-17-2022 06:41 AM
Matt-Huser
Occasional Contributor

I'm trying to generate fields that will tell field crews a replacement cost per feature and the current total cost of the replacement program based on the work they are doing.  I was expecting the scenario below to work but it does not. Is it possible to call other Arcade expression in other expressions?

For the individual feature's replacement cost: Expression1= (Length*Width)*[StaticMonetaryAmount]

For the total program replacements cost: Expression2 = SUM($layer,'Expression1')

0 Kudos
6 Replies
by Anonymous User
Not applicable

in Map Viewer Classic, open the table and left click on the column header.  Select Calculate from the popup and then choose from one of the functions on the right.

0 Kudos
Matt-Huser
Occasional Contributor

I don't think I'm seeing what you are.  I don't have any options like that. Arcade fields are locked and existing schema fields don't have a calculate options.

0 Kudos
jcarlson
MVP Esteemed Contributor

In short, no, it is not possible to reference one expression from another. You'll need to calculate the sum entirely on its own.

- Josh Carlson
Kendall County GIS
0 Kudos
Matt-Huser
Occasional Contributor

This was my fear. When I attempt to run the entire sum on its own using the $layer parameter, I'm getting values that are doubled.  Here is my attempt at the two different fields and their expression. When I sum the first field (Individual Features' replacement cost) I don't get the same value as the second field shows. It essentially doubles each time.

 

###Individual Features Replacement Cost###
Var PatchingAreaInYds = ($feature.WIDTH * $feature.LENGTH)/9
PatchingArea*26

##Summarizing All Features Replacement Cost###
Var ASPHALTLENGTH =sum($layer,'LENGTH')
Var ASPHALTWIDTH =sum($layer,'WIDTH')
Var PATCHINGAREAINYDS =(ASPHALTLENGTH*ASPHALTWIDTH)/9
PATCHINGAREAINYDS*26
0 Kudos
by Anonymous User
Not applicable

Robertc13_1-1655476687107.png

 

Robertc13_2-1655476758511.png

 

Robertc13_3-1655476834617.png

you obviously won't sum Longitude but this is the idea and how it appears for me

 

0 Kudos
Matt-Huser
Occasional Contributor

Thanks for the screenshots this was helpful for me to explore into.  This appears to be for only hosted data layers.  Also I think this is AGOL's version of Field Calculator which you wouldn't be able to run on a field created using an Arcade Expressions.

0 Kudos