I would assume from your post that this is coming from a survey? How are these "other" values getting into the `neighborhood` field? Are you concatenating choices from the survey?
Anyway, we can group all the "other" responses by using a list and matching against it. The Data Expression examples have yet to be updated to include this, but recent updates to the Arcade language enable us to use Push to populate an array, rather than using an index variable.
Try something like this:
// Get layer
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),
'itemID' , 0,
['neighborhood'], false);
// Define list of expected values
var categories = [
'Agressive Drivers',
'etc',
'etc'
]
// Empty feature array
var features = []
// Split choices, populate feature array
for (var feature in fs) {
var split_array = Split(feature["neighborhood"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
var cat = Trim(split_array[i])
if(Includes(categories, cat)){
var feat = {'attributes': {'split_choices': cat}}
} else {
var feat = {'attributes': {'split_choices': 'Other'}}
}
Push(features, feat)
}
}
// EDictionary w/ features
var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '', 'features': features};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
Do note, however, that the final "GroupBy" isn't necessary if the chart is all you need this for; the chart can handle the summing for you.
- Josh Carlson
Kendall County GIS