Dashboard - Expression Sum multiple Fields

3048
1
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

1 Reply
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));