Select to view content in your preferred language

arcade help: sum values that share common attribute

2372
4
Jump to solution
11-11-2022 07:54 AM
Labels (1)
CharlesCarlin
Emerging Contributor

Hi folks,

I could use some guidance on writing an arcade script for field calculator.

Here's what I would like to do:

I'm working within one feature layer.

I'd like to write a script that:
1. identifies polygons that share a common numeric identifier (FID),
2. sum numeric values from another attribute (value) from all polygons that share the common FID value , and
3. populate the sum in a new field (total_value)

Can anyone help me get started? Thank you!

Tags (1)
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

What would work is

Summary Statistics (Analysis)—ArcGIS Pro | Documentation

using FID as the 'case' field and a 'sum' for your 'statistics' field.

The if you need to get the values in a field in the original table, follow that by a "Join"

Join Field (Data Management)—ArcGIS Pro | Documentation


... sort of retired...

View solution in original post

4 Replies
DanPatterson
MVP Esteemed Contributor

What would work is

Summary Statistics (Analysis)—ArcGIS Pro | Documentation

using FID as the 'case' field and a 'sum' for your 'statistics' field.

The if you need to get the values in a field in the original table, follow that by a "Join"

Join Field (Data Management)—ArcGIS Pro | Documentation


... sort of retired...
CharlesCarlin
Emerging Contributor

Thank you! I was making things more complicated than I needed to. The summary stats and a join worked well.

0 Kudos
RemWilson
Occasional Contributor

Please correct me if I'm wrong, but it sounds like you want a script you can execute at-will, or do you want this to run automatically as new features are added/populated?

 

The expressions used should be simple enough... without seeing the fields and values, I would imagine it would look something like what's below.

 

var x = $feature.FID;

var y = $feature.[Field Name] //replace [Field Name] with the actual field name. This field may need to be passed/added as an array since I'm guessing you'll want to sum all the values and not individual record values

var z = $feature.[Field Name] //replace [Field Name] with the actual field name

 

if (x == ?) { // replace ? with the value you want to detect. if is a conditional statement that evaluates one thing to another and runs commands if the condition(s) are met.

sum ([y]); // The sum function can accept an array inside ([]) these brackets, or a number string input as (1,2,3)

z=y;

return z;

} else {

NULL

}

 

all the expressions I've written in arcade have generally been simple, so you may need to enlist help from those more experienced to get the sum function to work the way you envision; however, if you paste the above expression into an arcade editor, you should be able to modify and run it as I describe in the parts marked by //.

 

Hope this helps!

CharlesCarlin
Emerging Contributor

Thank you! Though I was able to achieve my result using the summary stats and a join, I'm still interested in playing with arcade to see what I can make work there. I'll give this a shot.

0 Kudos