# Field calculatur in ArcMap 10: How to specify field row?

I'm new to arcmap, so I'm not entirely sure about terminology which is probably why I can't seem to find the answer to this seemingly trivial question.

In the attribute table I want to be able to create a new field which takes the value from another field and adds the value from the previous row to it. My idea was simply to make a some kind of a `for` loop but to do that it seems I need to be able to specify a row number of a field, and I don't know how to do that.

Any help would be appreciated, ranging from a better solution to the answer to this specific question :).

Something like this should work. I assume you know how to get to the field calculator window for the column you want to calculate.

In field calculator, choose 'python', then put this in the code block:

``````lastValue = 0
def lagSum(col1,col2):
global lastValue
if lastValue:
sum = col2 + lastValue
else:
sum = 0
lastValue = col1
return sum
``````

Then in the expression box, enter

``````lagSum(!Field1!,!Field2!)
``````

Where Field1 and Field2 are the fields you want to use.

I adapted this code from one of the last examples here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Calculate_Field_examples/005s0000002m000000/

I am not sure that Keith's solution fits the bill because Johann wants the value of any given row to be equal to some field plus the value of the previous row. For this you will need to create a for loop as Johann suspected. The could be a few approaches to this question. One simple solution is to write a little ArcPy script.

Use an update cursor to loop over the rows in turn. This way you don't need to explicitly refer to a particular row (though you could use the FID field to get a particular row if you wanted). If you use a variable to store the value of the field you want to add to the next row, you can simply iterate over the rows with your cursor, updating your field as you go (remembering to also update your variable each iteration with the current row's 'add' field value).