Select to view content in your preferred language

How to use Arcade to filter a list of related features based on an attribute

637
5
Jump to solution
03-06-2025 01:16 PM
cepotts
Emerging Contributor

I hope this is the right place to post this.  

From searching around it appears that you cannot dynamically display a count of related features on a label or map tip, but the workaround is to write the information to a field, and then use that within the necessary expressions.  

I can successfully write the total number of related features to a field with the following code:

var relatedFeatures = FeatureSetByRelationshipName($feature, "<relationship_class_name>")
return Count(relatedFeatures)

 

 

That works great and returns a total of 5, which is how many features are related in the one feature that I am testing this on.  The image below shows the 5 related features.  

cepotts_0-1741295410703.png

However, the cable in that list is a sub-relation, and I don't want to include that feature in my count.  In this particular example, I want the final count to show as 4.  I was attempting to use the Filter() function to accomplish this, but I keep running into an invalid where clause error when adding the second line shown in the code below:

 

var relatedFeatures = FeatureSetByRelationshipName($feature, "<relationship_class_name>")
var filteredFeatures = Filter(relatedFeatures, "Data Type != 'cable'")
return Count(filteredFeatures)

 

I have attempted too many variations to recall.  Any tips to point me in the right direction?  I've been scouring through Google and ChatGPT and all of the examples returned lead me to exactly what I have written above.  

Thanks!

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You also have a space in the field name, which is probably its alias. Use the actual field name.

View solution in original post

0 Kudos
5 Replies
cepotts
Emerging Contributor

Here is the actual error message:

cepotts_0-1741296181202.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You have to use "<>" instead of "!=" in SQL statements

var filteredFeatures = Filter(relatedFeatures, "Data Type <> 'cable'")
0 Kudos
cepotts
Emerging Contributor

Thank you for the response.  That is one of the variations that I tried.  It still returns the same message.  

cepotts_0-1741357246764.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You also have a space in the field name, which is probably its alias. Use the actual field name.

0 Kudos
cepotts
Emerging Contributor

Thank you!  I did try that in other variations, but it was likely in completely different things that I was trying at the time.  I probably also still had the "!=" operator in there when attempting it.  Much appreciated!

0 Kudos