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:
| Year | Monthabb | |
| 2023 | 01-Jan | 1 |
| 2023 | 02-Feb | 1 |
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))