I want to calculate cumulative field values using an case field from another column in ArcGIS 10.4.
For example, if I have an "ID" column and "Count" column inside my attribute table, I want to calculate cumulative values for each year separately.
I have used this:
How to: Calculate cumulative shape length values of a feature class using the Field Calculator
I can do that if I select all rows with the same ID and run the field calculator, but that is a lot of manual work, so I want to use "ID" field as case field.
What is the best way to do that?
Solved! Go to Solution.
count = 0
id_list =[]
def cummulativeCount(increment, id_row_value):
global count
global id_list
id_list.append(id_row_value)
if len(id_list)>=2 and id_row_value == id_list[-2]:
count += int(increment)
elif len(id_list)<2:
count += int(increment)
else:
count = int(increment)
return count
cummulativeCount( !count_! , !id! )
count = 0
id_list =[]
def cummulativeCount(increment, id_row_value):
global count
global id_list
id_list.append(id_row_value)
if len(id_list)>=2 and id_row_value == id_list[-2]:
count += int(increment)
elif len(id_list)<2:
count += int(increment)
else:
count = int(increment)
return count
cummulativeCount( !count_! , !id! )
I don't know Python and I'm trying to follow what you did here. I have fields "Well ID", "Date", and "Injection". I want to calculate a cumulative sum of Injection values over time for each unique Well ID. Where would I substitute those field names into your code example?
Thanks,
John
Thank you very much!
нема на чему