Grouping dates in a serial chart using a data expression

08-08-2022 09:27 AM
Labels (1)
New Contributor II

I have a large table of inspections (a layer in a feature service) that includes a date field ('Inspections_date'; example format: 7/11/2022 2:23:00 PM) and spans several years. I would like to create a serial chart that groups the inspections by month and has two or more series to compare years. A simple excel chart looks like the attached (line chart works too). I know that using a data expression can probably get me there, but 1) I'm fairly new working with Arcade and 2) I can't figure out how to group by the date field to parse out the month. I'm also wondering if I should do some of this work in the feature service (grouping by month) instead of in Dashboard. Any guidance would be much appreciated! 


0 Kudos
1 Reply
New Contributor II

Using a similar post/thread I was able to create what I think is pretty close to what I need. However, I'm receiving a "failed to fetch" error when I test it. 

var p = Portal("https://XXX/")

// Get Inspections layer
var itemId = 'xxx'; 
var layerId = 2; 
var fields = ['InspectionDate', 'OBJECTID'];
var fs = FeatureSetByPortalItem(Portal(p), itemId, layerId, fields, false);
//var insp_month = Month(fs);
//var db_month = Decode (insp_month,0,'Jan',1,'Feb',2,'Mar',3,'Apr',4,'May',5,'Jun',6,'Jul',7,'Aug',8,'Sep',9,'Oct',10,'Nov',11,'Dec', 'wrong');

//Create dictionary
var monthDict = { 
  fields: [ 
    {name: 'month_num', type: "esriFieldTypeInteger"},
    {name: 'month_text', type: "esriFieldTypeString"},
    {name: 'insp_count', type: "esriFieldTypeInteger"},
  geometryType: "", 
  features: [], 

var index = 0; 

// Loop and store attributes 
for (var feature in fs) { 
  monthDict.features[index] = { 
   'attributes': { 
      'month_text': Text(feature['InspectionDate'], 'MMM'),
      'insp_count': feature['OBJECTID'], 

//Get month of inspection
var fs_Dict = FeatureSet(Text(monthDict));   
return GroupBy(fs_Dict, ['month_num', 'month_text'],
[{name: 'insp_by_month', expression: 'inspections', statistic: 'COUNT'}])


0 Kudos