AnsweredAssumed Answered

Arcade Popup Not Getting Sum of values from loop expression

Question asked by jfaron44 on Jul 9, 2019
Latest reply on Jul 10, 2019 by xander_bakker

I am implementing a custom expression which gets the result, a sum where applicable (i.e.when there are more than one results). The expression tests successfully in the expression editor, but the popup only returns the first result, i.e. does not get the sum of multiple results. The following expression yields a result of 24 when Test is clicked in the Expression editor, but the popup yields only the first of the three (in this case) results, the number 8 in this  case (three results with the value of 8 each). Here is the code, followed by a screenshot of the test result, and then the popup on the map (the attribute in question is the last line (Total kW on Applications).

var fc = FeatureSetById($map, /* PowerClerk Application Approved */ "DG_Transformer_Availability_Popup_test_2658")
var code = $feature["PARENT_ID"]
//var pizza = 26712474;
var sql = "TRANSFORMER_ID = " + code;
//var sql = "TRANSFORMER_ID = " + pizza;
//var sql = "TRANSFORMER_ID = 12157630"
Console(sql);
var applications = Filter(fc, sql);
var cnt = Count(applications);
Console(cnt);
var getAppKW;
var sumAppKW = 0;
if(cnt > 0){
Console(cnt);
for (var application in applications){
sumAppKW += application.APPLICATION_KW_AC
}
getAppKW = sumAppKW
}else{
getAppKW = "N/A"
}
if (IsEmpty(getAppKW) || (getAppKW == NULL)){
getAppKW = "No Data"
}
Console(getAppKW);
return getAppKW

Expression TestPopup Result

 

The line in the popup configuration (custom attribute display) is 'Total kW on Applications: {expression/expr5}', where expr5 is the expression quoted above.  This is on Portal for ArcGIS, 10.7.1. It seems that the Popup does not wait for the loop to complete, or there is an error or flaw in the code?

 

Thanks,

 

Jim Faron

Unisource Energy

Outcomes