I have a hosted feature layer in my portal in which I have a field named district and it has records like A, A, A, B, C, C. I essentially want to get total count of A, B, C and display it as label.
I understand this can be achieved using Count & Filter function of Arcade however, am on ArcGIS Enterprise 10.9.1 in which Filter function is not present.
As an alternate I have tried the following code:
var countf = 0
var test = $feature.districts
//var test1 = Split(test, ",")
for (var i = 0; i < test; i++){
if (test[i] == $feature.districts[i]){
countf = countf + 1
}
};
The code is not giving me any error however, am not getting correct result. I believe I am missing out on the syntax.
Any insights would be helpful.
Something like this?
// split the field into single districts
var districts = Split($feature.districts, ", ")
// get a count for each district
var counts = Dictionary()
for(var i in districts) {
var d = districts[i]
counts[d] = IIf(HasKey(counts, d), counts[d], 0) + 1
}
// combine districts and counts
var output = []
for(var d in counts) {
Push(output, counts[d] + " * " + d)
}
// return
return Concatenate(output, ", ")
Thank you @JohannesLindner for sharing this. I'll take a look at it.