AnsweredAssumed Answered

My python script calculates only the value of the immediate previous record

Question asked by GISGURU_001 on Apr 26, 2016
Latest reply on Apr 26, 2016 by GISGURU_001

My python script calculates only the value of the immediate previous record instead of calculating the values of all preceding records before that particular record. The example (the image) below is the undesired output;

Untitled.png

While the image below here is what i want to achieve;

Untitled2.png

This is my python script i used;

import arcpy
from arcpy import da
CensusBldForm = "CensusBldForm"
Calculated_EA1=0
with arcpy.da.UpdateCursor(CensusBldForm, ["OBJECTID", "EstimatedPopulationinEA", "Calculated_EA"]) as cursor:
     for row in cursor:
          Calculated_EA2 = row[1]
          row[2] = (Calculated_EA1 + Calculated_EA2)
          Calculated_EA1 = Calculated_EA2
          cursor.updateRow(row)

Kindly assist me with the above please.

Outcomes