How to create cumulative field calculation in Arcade?

04-01-2020 07:16 AM
Occasional Contributor

I have a simple table which records dates, types and locations of events.

How would I create a field or view in which the cumulative sum of events by date would be recorded as is diplayed below?

3,21.03.2020,not confirmed,Hamburg,8,3,3
4,21.03.2020,not confirmed,Hannover,8,3,3
6,24.03.2020,not confirmed,Hannover,8,3,3
Tags (1)
2 Replies
Occasional Contributor III

Hey Robert Buckley‌,

You can calculate the sum of all your layers like so:

var sum_values = SUM($layer,"Total")



If this answer was helpful please mark it as helpful. If this answer solved your question please mark it as the answer to help others who have the same question.

New Contributor

I know this is a little old, but I am having the same issue. I am still horrible at coding, so I appreciate your patience while I learn things. I'm a biologist and coding is more of a tool than my bread an butter, so I may have some jargon messed up.

The example solution above will achieve the sum of the total field input into every record of the table. However, this is not quite what either OP or I am looking to do.

Instead, we likely need to script an iterator that moves through each record and sums the preceding value to the next record.




My webmap has the acres calculated. What I need for various parties, is the cumulative sum field, or a running total of acres. Since we also want to try to keep this in AGOL and not move it back and forth between ArcGIS Pro, it would be nice if we had an arcade function to calculate this. 


In python, I can easily achieve this with a helper function:

expression: AccumulateValue(!Acres!)

code block:


total = 0
def AccumulateValue(arg):
value = arg
    global total
    if total:
       total += value
    else: total = value
    return total



I have attempted to make this into an arcade function, but seem to be missing something since it only produces "" in my target field.

Arcade attempt:


var total = 0;
function AccumulateValue(Acres){
   var value = $feature.Acres;
    if (total){
    return total+=value
    else {
    return total=value



Is there a break where/how I am calling the function? Is there a problem with how I am defining the "value" variable? Is the way I've identified the "total" variable as a global the correct process?

I wasn't really sure how to adapt the expression and code block I use in ArcGIS Pro to the AGOL scripting box so those are the areas where I think the script is particularly causing problems.

0 Kudos