ArcMap Field Calculator: Calculating Running Total with arcpy

I had a user with a series of GPS points (that were in chronological order) that they wanted to know the accumulated distance from the start to each point in their shapefile. First, we calculated the distance from each point to the previous point into a field called [DistFt].

Then, we hacked out this quick python function to accumulate the total distance in Arcmap’s Field Calculator:

totalDistance = 0

def accumulateDistance(inDist):
   global totalDistance
   totalDistance += inDist
   return totalDistance

And we called it:

accumulateDistance(!DistFt!)

accumulateDistAnd we got what we wanted.