Using calculate field to sum values based on two columns, number and string

862
2
03-31-2021 02:37 PM
MarilynLong1
New Contributor II

Hi,

I'm trying to use calculate field to add values to my column called Trail Length. I want to populate this column by adding together the trail sections that are part of the same trail.

Example:

Trail          Section Length      Trail Length

Trail A          .5                         (script that will add up the values in section length for Trail A, etc)

Trail A          .2

Trail B          5

Trail B           .3

Trail B           1

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

Summary Statistics (Analysis)—ArcGIS Pro | Documentation does it for you.  See the code sample to call it


... sort of retired...
MarilynLong1
New Contributor II

I've used summary stats to do this in the past but how do I incorporate that into the Field Calculator? I've been trying with Python and Arcade but don't know much about scripting and can't get it to work. This is what I have with Arcade:


GroupBy($layer, 'name', { name: 'trail_ft', expression: 'sec_length_ft', statistic: 'SUM'})

 

'name' is the column with the names of the trails. 'sec_length_ft' is the name of the column with the length of the sections that make up the trail. 'trail_ft' is the name of the column that I want to be updated.

0 Kudos