Select to view content in your preferred language

Arcade script to filter records and then rank them

809
4
Jump to solution
05-27-2023 01:32 PM
LJackson29
Occasional Contributor III

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
}
}

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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')

View solution in original post

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

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

 


... sort of retired...
0 Kudos
LJackson29
Occasional Contributor III

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

0 Kudos
KenBuja
MVP Esteemed Contributor

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')
0 Kudos
LJackson29
Occasional Contributor III

@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!

0 Kudos