Select to view content in your preferred language

Sum() returning Nan Value

2203
13
Jump to solution
04-20-2022 09:14 AM
godofsix
Emerging Contributor

I'm trying to compute the percentage of a field using the sum of all the fields: 

 

$feature.FullVaccin / Sum($feature.FullVaccin)

 

But every time I test, I get 1.... What am I doing wrong?

Tags (2)
0 Kudos
13 Replies
godofsix
Emerging Contributor

Sorry for the confusion... The FullVaccin is the fieldname on AGOL while Join_Count is for the original table in ArcPro..... and the table has not be joined with another table. 

($feature.Calculation * 1000)/Join_Count

This works but did not give the accurate percentage

0 Kudos
godofsix
Emerging Contributor

Whenever I use the (Sum($feature.Join_Count)) It returns the exact value for each row

0 Kudos
KimGarbade
Frequent Contributor

Hmmm... odd.  This code works in AGOL, and if I edit the Layer through a feature service in Pro (this is different test data, but the same code as I originally sent structure wise)

 

var myid = $feature.Work_Unit_No
var mysum = 0
var myfs = filter(featuresetbyname($datastore,"TestPoints",['TestInt'],false),'Work_Unit_No = @myid')
if(!IsEmpty(myfs)){
  var mysum = Round(($feature.TestInt/Sum(myfs,'TestInt'))*100,2)
}
return mysum

 

The reason your original code returned 1 every time was because it divided any number it found by itself:

$feature.FullVaccin / Sum($feature.FullVaccin)

So a tweak to the original code would be to create a feature set (in my example below called myfs) and pass that into the Sum function.  If I want the myfs feature set to return all the rows in the Layer's table I can just remove the filter from my original response.

KimGarbade_0-1650485008866.png

var myid = $feature.COJ_FacilityID
var mysum = 0
var myfs = featuresetbyname($datastore,"BogusPumps",['Integer1'],false)
if(!IsEmpty(myfs)){
  var mysum = ($feature.Integer1/Sum(myfs,'Integer1'))
}
return mysum

 If this doesn't work, I'm afraid I'm missing something that is right in front of me, but I just can't put my finger on.

0 Kudos
godofsix
Emerging Contributor

Thanks so much

0 Kudos