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?
Thanks!!!!!
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(
string_field,
'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
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