# Stuck on Relatively simple Arcade Popup calculation

463
4
05-06-2021 01:40 PM
Occasional Contributor III

Hi there - I have a simple scenario but am struggling with the intersect portion of the expression and want to make sure I can do what I want to do within the Popup profile for Arcade.

Example: I have a parcel layer on top of layers of irregular shaped polygons Zone1 and Zone2.  Sometimes a parcel (grey outline) intersects Zone1(pink), or 2(blue), or both/neither.

Each of the Zones has a "Cost" attribute as a double numeric data type. I'd like to click the parcel features and if they intersect one or more of the Zones have the costs added together and returned in the popup. Can someone nudge me in the right direction as far as an Arcade workflow, of which I'm sure there are many - thanks!

Tags (2)
1 Solution

Accepted Solutions
by
MVP Frequent Contributor

Yes, you can do this in the popup profile, and it's pretty straightforward. First you use intersects between the feature and the Zones layer, which produces a FeatureSet of Zone areas that intersect. Then you use sum to add up the costs.

``````var zones = FeatureSetByName(\$map, 'Zones-layer-name', ['field-to-sum'])

var int_zones = Intersects(\$feature, zones)

return Sum(int_zones, 'field-to-sum')``````
- Josh Carlson
Kendall County GIS
4 Replies
by
MVP Frequent Contributor

Yes, you can do this in the popup profile, and it's pretty straightforward. First you use intersects between the feature and the Zones layer, which produces a FeatureSet of Zone areas that intersect. Then you use sum to add up the costs.

``````var zones = FeatureSetByName(\$map, 'Zones-layer-name', ['field-to-sum'])

var int_zones = Intersects(\$feature, zones)

return Sum(int_zones, 'field-to-sum')``````
- Josh Carlson
Kendall County GIS
Occasional Contributor III

So if I have two zones with different costs associated with them, just repeat this and return for example something like:

``return Sum((int_zones1, 'field-to-sum') + (int_zones2, 'field-to-sum'))``

this is the part I'm stuck on - getting one total from these cases: sometimes there is a cost from Zone 1, sometimes costs from both Zones, and sometimes no costs. And Zones are on two different layers...

Occasional Contributor III

I ended up getting this to work, thanks so much for your help. You know what my error was?! The difference between " and ' string vs. number - ugh, want to beat my head on desk - thanks again!

``````var zone1 = FeatureSetByName(\$map,"Test - Zone1", ['Cost'])

var int1_Costs = Intersects(\$feature, zone1)

var zone2 = FeatureSetByName(\$map,"Test - Zone2", ['Cost'])

var int2_Costs = Intersects(\$feature, zone2)

return (Sum(int1_Costs, 'Cost') + Sum(int2_Costs, 'Cost'))``````
by
MVP Frequent Contributor

Oh, good! I'm glad you figured it out. Nothing like a good facepalm moment to keep you humble! I have one at least once a day.

- Josh Carlson
Kendall County GIS