"Warning The expression must return a number value."

1845
4
Jump to solution
03-11-2022 08:59 AM
CatherineBradley2
New Contributor II

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:

CatherineBradley2_0-1647017250918.png

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:

Warning
The expression must return a number value.
 
I have been on Google, AGOL help, & Arcade Help, and unfortunately I cannot find anything relating to me.  Any help would be appreciated.   
 
And one more question about AGOL web map/app:  Does what appears in the popup always appear in the legend and vice versa?
 
Thanks, Catherine 
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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.

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

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.

- Josh Carlson
Kendall County GIS
Henry_PeleshBW
Occasional Contributor

Hi Josh,

Thank you for the reply. Are you saying that Arcade can't be used to symbolize by two string fields? This seems odd - it feels like my expression should be able to yield good results. I got the same error with the expression below.

Henry_PeleshBW_0-1687965616403.png

@RussRoberts 

0 Kudos
Henry_PeleshBW
Occasional Contributor

@RussRoberts 

Sometimes all you need is to investigate a little deeper! (:

I got this to work properly using the script below. Just a simple change to establish a variable to return the results. Sorry for the bother!

Henry_PeleshBW_0-1687965983477.png

Henry_PeleshBW_1-1687966056584.png

 

 

0 Kudos
EricPescatore
Occasional Contributor

My frustration knows no bounds with ESRI.

0 Kudos