Hi @VeronicaArambula
I believe it is due to the date formatting - expecting in UNIX timestamp.
Also helped to modify the date (remove time) and logic for counting if false (changed to null)
// Reference layer using the FeatureSetByPortalItem() method.
var fs = FeatureSetByPortalItem(Portal('https://arcgis.com/'), '74d6c3d630c14458a3c23c71a19447ad', 0, ['*'], false);
// Empty dictionary to capture each value
var choicesDict = {'fields': [{ 'name': 'ID', 'type': 'esriFieldTypeString'},
{ 'name': 'dates', 'type': 'esriFieldTypeDate'},
{ 'name': 'morning', 'type': 'esriFieldTypeString'},
{ 'name': 'afternoon', 'type': 'esriFieldTypeString'},
{ 'name': 'night', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': []};
//define the start of date
var start = ToLocal(Date(1970, 0, 01, 0, 0, 0, 0))
// Store values in the dictionary
for (var feature in fs) {
var id = feature['ID']
//remove the time
var actdate = Date(Year(feature['actionDate']),Month(feature['actionDate']),Day(feature['actionDate']))
//Calculate the difference
var dt = DateDiff(actdate, start, 'milliseconds')
//make the value to null for count
var morning = Iif(feature['Shift_vehicles'] == 'Morning check (6-7am)',1,null)
var afternoon = Iif(feature['Shift_vehicles'] == 'Afternoon check (2-4pm)',1,null)
var night = Iif(feature['Shift_vehicles'] == 'Night check (11pm-1am)',1,null)
Push(choicesDict.features, {"attributes": {"ID": id,
"dates": dt,
"morning": morning,
"afternoon": afternoon,
"night": night}})
}
//return choicesDict
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
return fs_dict
// Return featureset
return GroupBy(fs_dict, ['ID', 'dates'],
[{ name: 'morning', expression: 'morning', statistic: 'COUNT' },
{ name: 'afternoon', expression: 'afternoon', statistic: 'COUNT' },
{ name: 'night', expression: 'night', statistic: 'COUNT' }]);
Cheers,
Tang
Cheers,
Tang