HOW TO
In ArcGIS Pro, the sum() function in the Calculate Field tool can be used to calculate the sum for each record from a list of numeric fields. However, when the feature class or table contains a large number of fields, it is impractical to manually select all the numeric fields.
The ArcPy script provided in this article can be used to calculate the sum for the values of all numeric fields in a feature class or table.
In this example, there are five numeric fields in the 'Point1' feature class, as shown in the next image.
import arcpy # Set the path to the feature class or the table table = r"" # Add a new field to the table arcpy.management.AddField(table, "SumField", "DOUBLE") # Use UpdateCursor to iterate through the rows of the table with arcpy.da.UpdateCursor(table, "*") as cursor: for row in cursor: # Initialize a variable to store the sum total = 0 # Iterate through each field in the row for i in range(len(row)): # Check if the field is numeric and not OBJECTID, Shape_Length, and Shape_Area if isinstance(row[i], (int, float, complex)) and cursor.fields[i] not in ['OBJECTID', 'Shape_Length', 'Shape_Area']: # Add the field's value to the total total += row[i] # Update the new field with the total row[cursor.fields.index('SumField')] = total cursor.updateRow(row)
The sum of the numeric fields for each feature is now populated in the new field, 'SumField'.
Get help from ArcGIS experts
Download the Esri Support App