# How to Calculate Cumulative Field Values in Arcmap

My problem is conceptually quite simple; In Arcmap 10.2, I wish to create a field which contains the cumulative values of another field in the same attribute table. For example, if the first three cells of the original field contained the values 1, 2, and 3, I would like my new field to contain the corresponding values of 1, 3, and 6. I have seen some solutions to this issue, but as I am not adept in coding I was unable to follow. If coding is necessary to resolve this issue, could the solutions please be presented in a step by step manner so that I am able to properly follow the procedure.

Thanks

## 1 Answer

You need a codeblock in your field calculator. The example below is with a Python parser

``````total = 0
def cumsum(inc):
global total
total+=inc
return total
``````

The first line initialize a variable to 0, then you define a function called cumsum with one argument.

for the incrementation, you want your variable to be "global" that will keep incrementing the value.

To call this code block, use

``````cumsum(!field_name!)
``````
• By the way, could you and someone else please post a similar script which I can use to calculate the totalof a given field? – jc22 Oct 4 '14 at 14:43
• use "statistics" or "summarize table" for that – radouxju Oct 5 '14 at 17:47
• How do you get cumsum() to work if the order is different? In my case it seems to be summing by the ID instead of the way I have sorted the data. – val Feb 18 '16 at 4:19
• @val as suggest in this thread, you can use the `sort` tool. Maybe it should be edited into the answer – dof1985 Mar 21 '17 at 16:15