Good morning all. I know nothing about Arcade, and what I thought would be a straight forward code, has not turned out that way. I have an AGOL map that I created a web map from. It consists of a feature service of houses of worship. There is a field in the att table called Affiliation. All I want to do in the legend is show :
Affiliation Name / number of affiliations
where the "Affiliation Name" is an entry in the Affiliation field of the att table, and "number of affiliations" is the total count number of each different affiliation. What I am striving for is:
Buddhist / 2
Catholic / 7
Etc.
My Arcade code is:
($feature.Affiliation) + " " + TextFormatting.ForwardSlash + " " + Count($feature.Affiliation)
When I click TEST, it looks exactly what I want:
Being overjoyed I figured something out, I gleefully clicked OK, only to have my Arcade scripting skills dashed when I got the disheartening message of:
Solved! Go to Solution.
Your $feature.Affiliation attribute is a string, so using Count on it is giving you the length of the string. In your test, that's just telling you that the text "Baha'i" is 6 characters long.
In order to get the count of features, you need to use the function against a FeatureSet, rather than a single feature. Your mention of the legend suggests you're doing this in the symbology settings? If so, there is unfortunately no way to access your other features in the symbology profile of Arcade.
What you're attempting is certainly possible elsewhere, but not in the symbology / legend.
As far as the error you're getting, that's generally the error you get when you attempt to add two non-numeric attributes to your symbology settings. You can add 2 or more fields to your symbology settings, but only if the additional fields are numeric. That's less to do with Arcade than the symbology settings in the web maps in general.
Your $feature.Affiliation attribute is a string, so using Count on it is giving you the length of the string. In your test, that's just telling you that the text "Baha'i" is 6 characters long.
In order to get the count of features, you need to use the function against a FeatureSet, rather than a single feature. Your mention of the legend suggests you're doing this in the symbology settings? If so, there is unfortunately no way to access your other features in the symbology profile of Arcade.
What you're attempting is certainly possible elsewhere, but not in the symbology / legend.
As far as the error you're getting, that's generally the error you get when you attempt to add two non-numeric attributes to your symbology settings. You can add 2 or more fields to your symbology settings, but only if the additional fields are numeric. That's less to do with Arcade than the symbology settings in the web maps in general.