Arcade: Calculate a Field

03-22-2023 11:27 AM
New Contributor III

Hi everyone!
I'm relatively new to Arcade and i'm trying to calculate a calculate Field in FeatureSet.

Basicly I have a String Field with domains. I want to create a new field that turns those string domains into numbers so I can have a custom order in my serial chart in Dashboards.

For exemple, I have the values: Very bad; Bad; Good; Very Good;
I need to create a new field that turns those values into numbers: Very bad = 0; Bad = 1; Good = 2; Very Good = 3;

Any idea on how to start?


0 Kudos
2 Replies
MVP Esteemed Contributor

Check out the Decode function, which is actually being used to "encode" your data in this case.

var string_field = $feature['your_field']

var coded_field = Decode(
    'Very bad', 0,
    'Bad', 1,
    'Good', 2,
    'Very Good', 3,
    -1 // the function wants a default value when no conditions are met, so we'll use -1

return coded_field
- Josh Carlson
Kendall County GIS
MVP Regular Contributor
var codes = {
    "Very bad": 0,
    "Bad": 1,
    "Good": 2,
    "Very good": 3,

if(HasKey(codes, $feature.StringField)) {
    return codes[$feature.StringField]
return 999 // default value if you forgot a code

Have a great day!
0 Kudos