I was able to create something that works really well after combining a few community posts if anyone comes across this in the future. This counts the number of times a multiple choice option was selected, and also renames the label to match what it was labeled as in Survey123.
Notes:
- This uses the Grouped Value option in Dashboard where the Category is set to the 'split_choices' field from the 'new' featureSet, then the Statistic is set to 'Sum' the 'split_count' field.
- The main step to get the relabeling to work is wrapping the "Trim" function in the 'decode_dict' to translate the values
- Be sure to add the decoded values as Categories in the dashboard Series tab, not the original labels.
// Reference layer using the FeatureSetByPortalItem() method.
var portal = Portal('https://www.arcgis.com')
var fs = FeatureSetByPortalItem(
portal,
'<ID#>',
0,
['<fieldnames>'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
//give the codes a new label to match what was entered in the survey
var decode_dict = {
"Local":"Born Here",
"Indigenous":"Native, Indigenous, or Aboriginal",
"Conflict":"Fleeing War, Tension, Persecution, Poverty; Seeking Refuge",
"Forced":"Slavery, Human Trafficking, Criminal Relocation",
"Career":"Opportunity - Employment or Education",
"Family":"Adoption, Marriage, or Reunification",
"Health":"Medical, Health, Environment, or Wellness",
"Colonization":"Colonization"
}
// Split comma separated types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["<fieldname>"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': decode_dict[Trim(split_array[i])]
}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(choicesDict);
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
Teresa Blader
Olmsted County GIS Specialist