Arcade Advanced Formatting - Feature to Feature Time Delta

01-18-2022 07:21 AM
New Contributor III

Is there a way to replicate dataframe.shift() from pandas in Ops Dashboard List or Table Widget using Advanced Formatting? I need to calc the time delta from feature to feature. I know I can pre-calculate for the entire dataset and add to my hosted table or calculate from the feature set via Data Expressions but that will be for the entire dataset. I want to be able to use the selector widgets to filter features then calculate the time delta dynamically.


0 Kudos
2 Replies
MVP Honored Contributor

Ordinarily, the DateDiff function is what you want. The trouble, though, is that the Advanced Formatting profile doesn't give you access to the other features in the layer. If you have the indicator set to "Feature", you can at least get at your single feature's attributes, but there's no way to reference another layer.

Well, there's the reference layer, but that only works with numeric statistics, not date fields. But then, date fields are just integers in different clothes, so maybe there's something we can do here.


It works, but it's super hacky.



Data Expression Layer

To get this to work, we do need to use a data expression, but just to convert our date to a number.

var portal = Portal('')

var fs = FeatureSetByPortalItem(
    ['some_date', 'type'],

var features = []
var feat

for(var f in fs){
    feat = {
        attributes: {
            date_num: Number(f['some_date']),
            type: f['type']
    Push(features, feat)

var fs_dict = {
    fields: [
        {name: 'date_num', type: 'esriFieldTypeSingle'},
        {name: 'type', type: 'esriFieldTypeInteger'}],
    geometryType: '',
    features: features

return FeatureSet(Text(fs_dict))

Indicator Settings

I've got my indicator looking at the data expression, and it's set to Feature. I also have a reference value set, and that's looking at the Maximum date number of the same expression. I'm also limiting it to a single feature.



Advanced Formatting

Now we've got two numbers that we've forced into the indicator's requirements, and a bit of Arcade can bring them back as dates.

var feat_date = Date($datapoint["date_num"])
var ref_date = Date($reference["max_date_num"])
var duration = Abs(DateDiff(feat_date, ref_date, 'days'))

return {
    topText: `Feature Date: ${Text(feat_date, 'DD MMM YYYY')}`,
    middleText: `Reference Date: ${Text(ref_date, 'DD MMM YYYY')}`,
    bottomText: `Date Diff: ${Round(duration)} days`


Selectors and Filtering

I've got two selectors set up. One targets the indicator value, one targets the reference. Both are based on the features in the expression.

If you wanted this to look nicer, you could amend the data expression to include additional fields for labeling, etc. 

And that should do it!


- Josh Carlson
Kendall County GIS
0 Kudos
New Contributor III

Thanks for the help. I haven't gotten it to work for my use-case yet but I'm working on it. If it does end up working, i'll nominate you as DS emeritus.

0 Kudos