[GIS] Sum value ArcGIS attribute (field calculator)

arcgis-desktopfield-calculatorpython-parser

I have in my columns attribute the following table (
follows the image):

enter image description here

"rank" (which is related to the order of my data);

"SL" (which is a linear measure of my object);

"testada" (the formula):

enter image description here

I wanted a help in the implementation of the formula tested in the field command of the calculator arcgis.

The columns "rank" and "SL" range, containing more or less attributes. That is, My data vary and what I'm showing is just a sample of my data set so was wanting a more dynamic formula. This formula has to read up to the last line, and return the sum of tested according to formula.

Best Answer

You can use a python "closure" construct or a global var, but I prefer not to use globals.

Expression:

calc_testada( !SL! )

Code block:

def testada(initval=0):
    #Remember state using a "closure" pattern
    #Note closure vars are read-only in Python 2x
    #So we use a mutable var like a list
    val = [initval]

    def _testada(SL):
       val[0] += SL
       return val[0]

    return _testada

calc_testada = testada()

enter image description here

Related Question