Good Afternoon All,
I am new to writing data expression to retrieve data for a hosted table in a dashboard and I am having trouble writing the expression to use in a pie chart on the Dashboard. For example, I need to write and expression that bring in the count of the Current Step field and the Project Name field. Ultimately the goal of the expression is to spring the attributes of the "Current Step' field and while providing a count of those attributes and filtering the counts by the Project Name. Below is my current code. I have been successful in get the Current Count to split and displaying the count of each of the choices but I am struggling to get the Project name to factor into the count. Will I need to write and expression to count the current step by the each individual project?
I appreciate any help and suggestions to solve this problem.
var portal = Portal('')
var fs = FeatureSetByPortalItem(
portal,
'*',
0,
['Current_Step'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
var loc = FeatureSetByPortalItem(
portal,
'ddd2e78398c14777b49f902b9b289ada',
0,
['Project_Name'],
false
);
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature['Current_Step'], "(")
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': 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(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
Thank you,
Janelle