I have a COVID-19 dashboard that needs to show the change in the number of cases since the last report. I have a table with a date field but the reporting isn't daily, so I can't just filter by things like "Today" or "Yesterday" etc. I need to find the max date and second to max date from the report records and report the change and/or rate of change.
The data looks something like this:
County | NewCasesToday | Date |
Eaton | 12 | 05/26/2020 |
Eaton | 10 | 05/27/2020 |
Eaton | 14 | 05/29/2020 |
Eaton | 12 | 05/30/2020 |
Eaton | 3 | 06/3/2020 |
I've used Arcade for simpler calculations, but this one has me stuck. Any help would be most appreciated.
Solved! Go to Solution.
Thanks for that. Much appreciated. I'm not all that familiar with arcade yet so I'm thinking the best approach for me is to add a previous count field to the hosted feature class. Next, I'll start doing my edits in Pro rather than on AGO directly so all edits are sent simultaneously when I save them. Before I do my daily edits to update the current counts, I'll just do a field calc on the previous count field, pushing the current values over. Then I update the current case counts. The indicator should then (in theory) work because I can provide an attribute value as a reference. Takes a few more seconds to do it that way, but it should be foolproof, I hope.
I am trying to do something similar and calculate the the change in lake level from the most recent reading to the previous reading. I tried the code and just changed the feature and date fields to start with and get and error at the ; at the end.
Test execution error: Unexpected token '${value}'.. Verify test data.
// get related records
var fs = FeatureSetByRelationshipName($feature, 'lake_level');
// sort the related records and get top 2
fs = Top(OrderBy(fs, '_date DES'), 2);
// get the latest and previous features
var result = Null;
if (Count(fs)==2) {
var cnt = 0;
for (var f in fs) {
cnt += 1;
if (cnt == 1) {
var f_latest = f;
} else if (cnt == 2) {
var f_prev = f;
}
}
// determine NewCasesToday and calculate increment
var cases_latest = f_latest.NewCasesToday;
var cases_prev = f_prev.NewCasesToday;
result = cases_latest - cases_prev;
}
// return the result
return result;
Any help would be appreciated. Thanks