Select to view content in your preferred language

Arcade expression for change since last edit?

4572
11
Jump to solution
05-26-2020 10:59 AM
ScottStopyak
Frequent Contributor

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:

CountyNewCasesTodayDate
Eaton1205/26/2020
Eaton1005/27/2020
Eaton1405/29/2020
Eaton1205/30/2020
Eaton306/3/2020

I've used Arcade for simpler calculations, but this one has me stuck. Any help would be most appreciated.

0 Kudos
11 Replies
ScottStopyak
Frequent Contributor

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.

AJM
by
Regular Contributor

@XanderBakker 

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

0 Kudos