Select to view content in your preferred language

Monthly Running Total

54
1
Monday
Labels (1)
CoreyarjRobinson
New Contributor

Hello, 

 

I have been trying to create a running total data expression using the following example: Solved: Cumulative Chart With Arcade Expression - Esri Community. However, I would like the running total to be on both year and month. As a result, I been trying to modify the example arcade script to include two loops, one for year and one for month. Unfortunately, I can't seem to get it. Any suggestions? 

Example Data:

YearMonthabb
incidentcount
202301-Jan1
202302-Feb1


Arcade:

var year_value = OrderBy(Distinct(fs, 'year'), "year ASC")
var month_value = OrderBy(Distinct(fs, 'monthabb'), "monthabb ASC")

//output featureset dictionary
var out_dict = {
  fields: [
    {name: 'year', type: 'esriFieldTypeInteger'},
    {name: 'monthabb', type: 'esriFieldTypeString'},
    {name: 'year_sum', type: 'esriFieldTypeInteger'}    
  ],
  geometryType: '',
  features: []
}

//loop over each year, getting the cumulative count and per-year count, add to output dict
for (var y in year_value) {
  var yr = y['year']

  for (var m in month_value) {
    var mn = m['monthabb']

  Push(
    out_dict['features'],
    {
      attributes: {
        year : yr,
        month : mn,
        year_sum: Sum(Filter(fs, `year = ${yr} && monthabb = '${mn}'`), 'incidentcount')
      }
    }
  )
}
}

return FeatureSet(Text(out_dict))


 

 

0 Kudos
1 Reply
CodyPatterson
MVP Regular Contributor

Hey @CoreyarjRobinson 

When you say "can't get it right" what is it doing that tells you that, does it produce an error or just produces nothing? If it produces an error, could you link it here?

Cody

0 Kudos