Can you use data expressions in ArcGIS Dashboards to perform math with a pervious record? The data is stored in ArcGIS Server and pulled into ArcGIS Online .
Solved! Go to Solution.
Can you give some examples? It's hard to know how the expression is failing without knowing what it's actually doing.
Yes! Provided you can identify what "previous" means with some record sorting, etc., you can easily write an expression that uses the previous record's value to calculate something else.
Can you share the expression?
I'm not sure how you ended up with that expression. The FeatureSetByPortalItem function requires you to specify the layer index, and it won't get past the second line as its written. Even if it did, it needs to return a FeatureSet object.
The way Data Expressions work is a bit different from other Arcade profiles. If you haven't yet, take a look at some of the expressions here:
https://github.com/Esri/arcade-expressions/tree/master/dashboard_data
In particular, note how you need to first define a dictionary with the fields defined and an empty array for the features. Then you need to loop through every feature in your FeatureSet to push attributes to that dictionary. It will look very different from what you have posted.
var portal = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(
portal,
'fcb8c011c9f44ad09e735683da808b41',
0,
['some_field'],
false
);
var out_dict = {
fields: [
{name: 'some_field', type: 'esriFieldTypeInteger'},
{name: 'difference_from_last', type: 'esriFieldTypeInteger'}],
geometryType: '',
features: []
}
var prev_val = 0
for (var f in fs) {
Push(
out_dict['features'],
{
attributes: {
some_field: f['some_field'],
difference_from_last: f['some_field'] - prev_val
}
}
)
prev_val = f['some_field']
}
return FeatureSet(Text(out_dict))
Well, that can depend on the data itself. Is the field actually an integer, or does it need to be converted?
Are you records already in the appropriate order? You may need to use Sort if not.
What are you getting back, if anything?
Can you give some examples? It's hard to know how the expression is failing without knowing what it's actually doing.