I need a way of calculating the total sum of the values in an existing field and displaying this value in the corresponding cells of another field. In other words, I want this second field to display the same value in each row, being the total of the values of the source field. I am using ModelBuilder and will be operating this function on multiple datasets, as such, this process needs to be automatic. I have no experience with coding and very little in how to implement it.
I recently asked a similar question, which was: "How to calculate the cumulative values of a field". This question was answered and resolved with the following python parser in the code block of the field calculator:
total = 0
def cumsum(inc):
global total
total+=inc
return total
Where the code block was called using:
cumsum(!field_name!)
As I was able to successfully implement this parser, I would prefer if some one could adapt this example to calculate the total sum of the values in a field rather than their cumulative sum.
Answer
This can be achieved with a relatively simple model, no programming required! The model is below:
I use the summary statistics tool to sum your first field and place this value in an in_memory table. Then use the get Field value tool (a model only tool) to get that value. Then a simple calculate field tool on your second field using in-line substitution (in this case %SUM value%). The output of the Get Field value tool is a precondition to the calculate field tool so it runs in the correct order.
No comments:
Post a Comment