Select to view content in your preferred language

Dashboard - Arcade calculation from 2 Layers

689
2
Jump to solution
10-12-2023 01:26 PM
Jack_G
by
New Contributor

Hi, I am trying to create a simple calculation which works in the Arcade Expression, but says its unable to execute within a Dashboard Element (Indicator).

In Dashboards, I add Element > Indicator > select the 'New Data Expression' enter the code and its valid, but when i click 'Done' i get 'Unable to execute Arcade script'

Arcade_works.PNG

AIRS_Unabletoexecute.jpg

 

 

 

 

 

 

 

 

 

Code:

//***Visitors***//

var OfficeVisitors = FeatureSetByPortalItem (Portal('portalURL'),  'layerID',  0,   ['*'],   false);

var Visitors = Sum(OfficeVisitors, 'visit_cnt');

//***Incident***//

var Incidents = FeatureSetByPortalItem (Portal('portalURL'), 'layerID', 0,  ['*'], false);

var Total_Incidents = Count(Incidents);

//***Incidents 100K Visitors***//

var IncidentsPer100K = (Incidents/Visitors)*100000

return IncidentsPer100K

 

Thank You,

Jack

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Data Expressions have to return a FeatureSet. If you really just want that single number, you can try this:

//***Visitors***//

var OfficeVisitors = FeatureSetByPortalItem (Portal('portalURL'),  'layerID',  0,   ['*'],   false);

var Visitors = Sum(OfficeVisitors, 'visit_cnt');

//***Incident***//

var Incidents = FeatureSetByPortalItem (Portal('portalURL'), 'layerID', 0,  ['*'], false);

var Total_Incidents = Count(Incidents);

//***Incidents 100K Visitors***//

var IncidentsPer100K = (Incidents/Visitors)*100000

var out_dict = {
  fields: [
    {name: 'incidentsPer100K', type: 'esriFieldTypeDouble'}
  ],
  geometryType: '',
  features: [
    { attributes: { incidentsPer100K: IncidentsPer100K }}
  ]
}

return FeatureSet(out_dict)

 

But really, I think you could do this with a reference value as well.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

Data Expressions have to return a FeatureSet. If you really just want that single number, you can try this:

//***Visitors***//

var OfficeVisitors = FeatureSetByPortalItem (Portal('portalURL'),  'layerID',  0,   ['*'],   false);

var Visitors = Sum(OfficeVisitors, 'visit_cnt');

//***Incident***//

var Incidents = FeatureSetByPortalItem (Portal('portalURL'), 'layerID', 0,  ['*'], false);

var Total_Incidents = Count(Incidents);

//***Incidents 100K Visitors***//

var IncidentsPer100K = (Incidents/Visitors)*100000

var out_dict = {
  fields: [
    {name: 'incidentsPer100K', type: 'esriFieldTypeDouble'}
  ],
  geometryType: '',
  features: [
    { attributes: { incidentsPer100K: IncidentsPer100K }}
  ]
}

return FeatureSet(out_dict)

 

But really, I think you could do this with a reference value as well.

- Josh Carlson
Kendall County GIS
0 Kudos
Jack_G
by
New Contributor

For the FeatureSet return, you have to use 'text' as well to get results.   FeatureSet(Text (out_dict)) worked. 

 

Do you or know how i can add a date filter to the portalitem?  I want to show visitor counts to say where 'day_dt' >= '01/01/2016'  I assume I have to add the filter around the SetPortalitem based on a few other posts but can't seem to get it working right. 

 

Then ultimately i wanted to somehow display the incidents per 100K visitors for each month somehow... Right now the visitor table i have goes back to 2004 and the incident table is from 2016. So i need to at least filter the visitor counts to "is or is after" 01/01/2016"

Then I would somehow like to groupby month somehow of incidents per 100K visitors per month

output to be:

{ attributes: 
{ Jan 2016: IncidentsPer100K}
{ Feb 2016: IncidentsPer100K}
{ March 2016: IncidentsPer100K}
{ Apr 2016: IncidentsPer100K}
{etc: etc}}

 

0 Kudos