Ability to calculate statistics from other Indicators in the ArcGIS Dashboard

263
0
02-16-2024 03:28 PM
Status: Open
RichardFreer2
New Contributor II

Developing a Dashboard for Pavement Maintenance utilizing Asset and Task Data.  One of the Indicators that I would like to create requires creating two separate FeatureSets with the Arcade Profile for FeatureSetByPortalItem.  It's easy enough to get an indicator to display the totals for each, but I have been having real difficulty writing the Arcade Expression to get the percentage of Lane Miles Rehabilitated.  The simple expression is (Total Lane Miles Rehabilitated) / (Total Lane Miles Publicly Maintained), however these totals are from two separate datasets, and for those of us not familiar with Arcade expressions, can find it daunting to dive into the limited resources out on writing the expressions.Pavement Area Dashboard.JPG

This photo is a draft for the dashboard, the indicator in the bottom left is my attempt at the arcade script:

// Connection to ArcGIS Portal
var portal = Portal('Portal URL')

//FeatureSet for the Calculation
//Tasks_Polygon_Pavement
var Tasks = FeatureSetByPortalItem(portal, '1ab4ab9425964ede9c1faaef0aeae1a7', 2,['rehabilitation', 'number_of_lanes', 'lane_miles', 'totalcost'], false );
var Rehab = Filter(Tasks, "rehabilitation = 'Yes'")
var RMiles = sum(Rehab, "Lane_Miles")

//Engineering_Assets_PavementArea
var Assets = FeatureSetByPortalItem(portal, 'fdc330cc0c86465fb11b4fd271f2f408', 5,['*'], false);
var TMiles = sum(Assets, "Lane_Miles")

var fs_dict = {
fields: [{name: 'Rehab_Percentage', type: 'esriFieldDouble'},
{name: 'Rehab_Miles', type: 'esriFieldDouble'},
{name: 'Total_Miles', type: 'esriFieldDouble'}],
geometryType: '',
features:
[{attributes:
{'Rehab_Percentage': Round((SUM(Rehab, 'Lane_Miles')/SUM(Assets, 'Lane_Miles'))*100,2),
'Rehab_Miles': Round((SUM(Rehab, 'Lane_Miles')),2),
'Total_Miles': Round((SUM(Assets, 'Lane_Miles')),2)
}}]};

return FeatureSet (Text(fs_dict))

 

Like I said, I'm not an expert at all when it comes to scripting, but I'm trying to figure it out.  I'm pretty certain my problem with the script lies in the Dictionary, was able to view results from everything above as I wrote the expression.  The script results are:

Result:  (Blank)

Type:  FeatureSet

If you were able to write a simpler Arcade Script where "Indicator A Value" / "Indicator B Value" = "Indicator C Value", it would make life much easier for those of us that can't script like the Pros.  From what I've been able to comprehend, using the FeatureSetByPortalItem, things get more complicated/restrictive of what you can do, so maybe I'm just trying something that isn't possible.

After grueling attempts, I was able to get a working expression for the Percentage of Total Lane Miles Rehabilitated, but now to add a filter for dates:

// Connection to ArcGIS Portal
var portal = Portal('Portal URL')

//FeatureSet for the Calculation
//Tasks_Polygon_Pavement
var Tasks = FeatureSetByPortalItem(portal, '1ab4ab9425964ede9c1faaef0aeae1a7', 2,['rehabilitation', 'number_of_lanes', 'lane_miles', 'totalcost'], false );
var Rehab = Filter(Tasks, "rehabilitation = 'Yes'")
var RMiles = sum(Rehab, "Lane_Miles")

//Engineering_Assets_PavementArea
var Assets = FeatureSetByPortalItem(portal, 'fdc330cc0c86465fb11b4fd271f2f408', 5,['*'], false);
var TMiles = sum(Assets, "Lane_Miles")

var PMiles = Round((RMiles / TMiles * 100),2)

var out_dict = {
fields: [
{name: 'Percent_Rehab', type: 'esriFieldTypeDouble'},
{name: 'Last_Treatment_Date', type: 'esriFieldTypeDate'},
],
geometryType: '',
features: [
{attributes: { Percent_Rehab: PMiles}}
]
}

return FeatureSet(Text(out_dict))