Select to view content in your preferred language

Dashboard - Expression Sum multiple Fields

4021
2
Jump to solution
07-13-2021 03:21 PM
RickeyFight
MVP Regular Contributor

I am trying to sum our plant production from multiple sources. 

 

 

 

var portal = Portal("");
var fs = FeatureSetByPortalItem(
  portal,
  "",
  1,
  [
    "Date_",
    "W_F_MGD",
    "E_F_MGD",
    "TOTAL_W_E_MGD",
    "TID_FLOW_MGD",
    "REEDER_Percent_FULL",
    "TAP_FLOW_MGD",
    "PLANT_PRODUCTION_MGD"
  ],
  false
);


// Find the most recent date from the date field to filter the FeatureSet for the latest record
var TotalProduction = Round(Sum(fs, "PLANT_PRODUCTION_MGD")+Sum(fs, "TAP_FLOW_MGD"));
return TotalProduction;

 

 

 

 

I want to sum the TAP, TID, and Plant production fields.  I am getting errors even with the code above. What am I doing wrong.  

 

Update:

using this I was able to sum in the script 

https://www.esri.com/arcgis-blog/products/ops-dashboard/announcements/introducing-data-expressions-i...

RickeyFight_1-1626216234387.png

Test shows a result but I cannot select it

RickeyFight_0-1626216217222.png

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

I'm guessing this is a data expression? The issue is that you have to return a featureSet.  I would just construct a simple feature set with the value you need as a single row.

https://doc.arcgis.com/en/dashboards/get-started/create-data-expressions.htm

https://doc.arcgis.com/en/dashboards/reference/authoring-data-expressions.htm

var newDict = { 
  'fields': [{ 'name': 'totProd', 'type': 'esriFieldTypeDouble'}], 
  'geometryType': '', 
  'features': [{   
            'attributes': {   
                'totProd': TotalProduction,    
            }}]   
}; 


return FeatureSet(Text(newDict)); 

 

 

View solution in original post

2 Replies
DavidPike
MVP Frequent Contributor

I'm guessing this is a data expression? The issue is that you have to return a featureSet.  I would just construct a simple feature set with the value you need as a single row.

https://doc.arcgis.com/en/dashboards/get-started/create-data-expressions.htm

https://doc.arcgis.com/en/dashboards/reference/authoring-data-expressions.htm

var newDict = { 
  'fields': [{ 'name': 'totProd', 'type': 'esriFieldTypeDouble'}], 
  'geometryType': '', 
  'features': [{   
            'attributes': {   
                'totProd': TotalProduction,    
            }}]   
}; 


return FeatureSet(Text(newDict)); 

 

 

SIG-EscutismoCNE
Emerging Contributor

Hello,

I’m trying to write an expression in the dashboard to add two layers in a certain field (n_lobitos in both)

I’m not getting it. Any help?

 

I’ve seen the sample below but it’s different.

 

https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/CalculationAcrossFields.md

----------------------------------------------------------------------------------

var portal = Portal('https://www.arcgis.com/')
var fs = [
  FeatureSetByPortalItem(portal'8fadffa6772f428db8ffa703f9ebc61b'layerID, ['n_lobitos'], false),
  FeatureSetByPortalItem(portal'43e99df1123d454cb3d3e48ae5cfa462'layerID, ['n_lobitos'], false),
]
var running_sum = 0

for (var set in fsets) {
  var set_sum = Sum(fsets[set], 'n_lobitos')
  Console('featureset sum:'set_sum)
  running_sum += set_sum
  Console('running sum:'running_sum)
}

return FeatureSet({
  fields: {name'sum_n_lobitos'type'esriFieldTypeInteger'}, // or whatever field type it is
  geometryType'',
  features: [{attributes: {sum_n_lobitosrunning_sum}}]
0 Kudos