Hello,
I'm trying to write an expression to count the number of values, for each type within a field (i.e. region A, region B) to populate a second field with the results, with Attribute Rules. So far I can select the region for each entry but I have not been able to filter the count for each entry by its region. My code so far:
When ($feature.Region=='A',Count($feature.Region), $feature.Region=='B',Count($feature.Region),1000)
I tried using the filter but I could not get it to work.
Any suggestions?
Thanks
Randy
You are on the right track using the Filter function. In your code, the Count is just returning the number of characters in the Region field for the $feature, which will always be 1 since its either A or B. You need to pass a FeatureSet into the Count to get a record count. For the Filter function, I am passing $layer, which is the layer the $feature belongs to. Then I am filtering the features that have the same Region as the $feature and getting the count.
return Count(Filter($layer, "Region = '"+$feature.Region+"'"))
Thanks Justin_Greco, I believe your expressions is correct but since I am using ArcGIS pro 2.7.1 it does not recognize $layer. I am looking with my IT department to see if I can update my pro version to 3.2 which would allow me to use your expression.
Thanks again
$layer might not be available for attribute rule profile, so I think you can use FeatureSetByName, I'm not sure what your layer name is, so replace "Regions" with your layer's name.
var fs = FeatureSetByName($datastore, "Regions")
return Count(Filter(fs, "Region = '"+$feature.Region+"'"))