In one of the fields of my attribute table, I have been trying to fill the rows with the numerical difference between the value of 2 records from another field.
Basically, in a spreadsheet, the process would be B2 = A2 - A1, B3 = A3 - A2, B4 = A4 - A3, etc.
In my attribute table, the process would look like this : the value of OID 2 in field B equals the difference between the values of OID 2 & 1 in field A.
I don't know what the script, either in Arcade or Python, could be. Does anyone have an idea?
Solved! Go to Solution.
Python:
#YourField =
calc(!OBJECTID!)
#Code Block
last_val = None
def calc(val):
global last_val
diff = (val - last_val) if last_val is not None else None
last_val = val
return diff
Arcade
var oid = $feature.OBJECTID
var last_row = First(OrderBy(Filter($featureset, "OBJECTID < @oid"), "OBJECTID DESC"))
if(last_row == null) { return null }
return $feature.OBJECTID - last_row.OBJECTID
Python:
#YourField =
calc(!OBJECTID!)
#Code Block
last_val = None
def calc(val):
global last_val
diff = (val - last_val) if last_val is not None else None
last_val = val
return diff
Arcade
var oid = $feature.OBJECTID
var last_row = First(OrderBy(Filter($featureset, "OBJECTID < @oid"), "OBJECTID DESC"))
if(last_row == null) { return null }
return $feature.OBJECTID - last_row.OBJECTID
Thanks Johannes. I used the Python script and it worked fine.