I am trying to calculate a field in Pro based off another field using the When function in Arcade. The field I am calculating off (TYPE) is numeric with values such as 1,2,3,4. The field I am calculating is text.
I use Calculate field and select Arcade for Expression Type and add the following text:
var type = $feature.TYPE;
When([type = 1, 'Primary', type = 2, 'Secondary', type = 3, 'Tertiary'], 'N/A')
Unfortunately, when I verify the expression I get the following error message
"Invalid Expression
Error 0 on line 2.
Close square brace expected."
I thought I was following the sample in the documentation, so I'm confused that I would get an error.
Any help to solve this issue is greatly appreciated.
Solved! Go to Solution.
Use this:
var $feature.TYPE;
When(type == 1, 'Primary', type == 2, 'Secondary', type == 3, 'Tertiary', 'N/A')
When(density < 50, 'low', density >=50 && density < 100, 'medium', density >= 100, 'high', 'n/a');
from here
https://developers.arcgis.com/arcade/function-reference/logical_functions/
I think the square braces was being taken too literally in your expression
That is the documentation I was reading when attempting to use the When expression. I thought I would be able to use = in my expression as the documentation does not indicate you cannot use =, but that seems to be the problem.
When I changed my syntax to:
When(type < 2, 'Primary', type > 1 && type< 3, 'Secondary', type > 2, 'Tertiary', 'N/A')
I was able to verify the expression and successfully calculate the field.
If I was to use the square braces in my expression I get an error, so the documentation seems misleading in that regard.
I think the square brackets are referring to a list of optional parameters, not an actual list
Use this:
var $feature.TYPE;
When(type == 1, 'Primary', type == 2, 'Secondary', type == 3, 'Tertiary', 'N/A')