Hi -
I am new to arcade still and am trying to write a code that will filter records where PR_TOTSCORE is not NULL, and then rank the records on PR_TOTSCORE. The below code is working, but does not include the filtering part. I have tried different approaches but haven't been successful yet. Any suggestions?
var setfeatures = FeatureSetByName($datastore, "Stormwater Project");
//Need filter step here that filters records where PR_TOTSCORE is not NULL. I have tried using !IsEmpty but have not been successful.
// order the layer
var ordered = OrderBy(setfeatures, 'PR_TOTSCORE DESC')
var rank = 0
// iterate over the ordered layer
for(var f in ordered) {
// increase the rank
rank++
// if the feature we're looking at is the feature we clicked on, return the current rank
if(f.OBJECTID == $feature.OBJECTID) {
return rank
}
}
Solved! Go to Solution.
Use the Filter function like this:
var setfeatures = FeatureSetByName($datastore, "Stormwater Project");
//Need filter step here that filters records where PR_TOTSCORE is not NULL. I have tried using !IsEmpty but have not been successful.
var filteredFeatures = Filter(setfeatures, 'PR_TOTSCORE IS NOT NULL');
// order the layer
var ordered = OrderBy(filteredFeatures, 'PR_TOTSCORE DESC')
your lack of code formatting makes it hard to decipher where an error may be
Code formatting ... the Community Version - Esri Community
Have a look at this and modify to suit
Solved: Using arcade to rank polygons - Esri Community
Hi Dan -
Thanks for the response. Sorry for the code formatting - that is how it pasted into the post, not how it looks in reality. The post you pointed me to is where I actually got the code, but that does not include the filter statement that I am in need of.
Leila
Use the Filter function like this:
var setfeatures = FeatureSetByName($datastore, "Stormwater Project");
//Need filter step here that filters records where PR_TOTSCORE is not NULL. I have tried using !IsEmpty but have not been successful.
var filteredFeatures = Filter(setfeatures, 'PR_TOTSCORE IS NOT NULL');
// order the layer
var ordered = OrderBy(filteredFeatures, 'PR_TOTSCORE DESC')
@KenBuja Thank you - that worked! It seems so simple, but I could find nothing about using NULL/ IS NOT NULL in the arcade documentation, but now I see that you can include a sql expression within the Arcade statement. So much still to learn!
Thank you!