Sum of features with common value in field in pop-up using Arcade?

1248
9
12-11-2019 12:48 PM
DaneWeeks
New Contributor

I have several thousand points representing trees and their proximity to hundreds of utility lines.  Each tree and line has its own unique ID.  Is it possible to calculate the sum of trees for each line within the popup?  For example, I click on a tree point near line 123, and the pop-up window would read "213 trees remain on line 123".  An important distinction is that the lines themselves are not loaded into the web map, this would simply be based on the field in the tree point attribute field.  

0 Kudos
9 Replies
XanderBakker
Esri Esteemed Contributor

Hi Dane Weeks ,

So, from what I understand you just want to work with the layer containing the trees and each tree has a line ID too. So you click on a tree, read out the line ID and get the count of the trees with that line ID. If this is the case it would work like this:

var lineID = $feature["your line ID field name"];
var sql = "your line ID field name = '" + lineID + "'"; // for a text ID field
var sql = "your line ID field name = " + lineID; // for a numeric ID field
return Count(Filter($layer, sql));
DaneWeeks
New Contributor

Hi Xander,

Thanks for the response. Unfortunately, I didn't have any luck.  I received an error "feature is immutable".  I realize I poorly explained my issue.  I have thousands of tree points, that are associated with 100s of lines.  Each tree is only associated with one line.  The lines are represented spatially, they are only included in a string value in the table of the tree feature.  Here is my attempt:

var line = $feature["line_id"];
var sql = ["line_id"] = '" + line + "'";
return Count(Filter($layer, sql));
0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi dane.weeks ,

Question... where are you configuring this expression? In the pop-up or somewhere else?

0 Kudos
DaneWeeks
New Contributor

I clicked "configure pop-up" on the feature layer in my web map.  Then "add expression".

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi dane.weeks ,

I have seen this error in the past, but this was related to creating objects. Would it be possible to share the map and content to a group and invite me ("xbakker.spx") to have a look at the data?

0 Kudos
DaneWeeks
New Contributor

Unfortunately, sharing the content with you would be extremely difficult, if possible at all.  That map is nested in my employer's portal site.  I'd be more than happy to do a chat session or screen session if you think that would be beneficial.   

Edit: I made some mild changes to the syntax and ended up getting an error that stated that filter function does not exist.  I double-checcked that in my function list and that is correct.  Does that mean it may be a version issue?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Dane Weeks , 

With your last comment, I am understanding that you are using ArcGIS Enterprise. For ArcGIS Enterprise, what functions are available depends on the version of your implementation. I'm not entirely sure when filter was introduced, but I guess you will need 10.7 or above. What version do you have?

0 Kudos
DaneWeeks
New Contributor

I believe my organization has version 10.6.1, which would explain why many of the functions listed in the help documentation don't appear on my list. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Dane Weeks ,

What I am seeing in the release notes (Release Notes | ArcGIS for Developers ) is that the function was released in version 1.5 of Arcade (December 2018 in AGOL). This means that it was introduced at 10.7.0 in ArcGIS Enterprise. I'm sorry to have to tell you that to take advantage of the functionality, you will have to update to a newer version. 

edit: Version Matrix | ArcGIS for Developers (this is a better reference for comparing versions)