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?
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:
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.
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.
Thanks so much
Whenever I use the (Sum($feature.Join_Count)) It returns the exact value for each row
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
Is "FullVaccin" off the page to the left?
Is the table joined with another table?
If you run a calc on Percentage again, and this time just do something simple like
(just using data I see in your table); it will return a useless number, but does that result also show 1 every time?
Long
Hmmm... what data type is FullVaccin? Also, are you using Field Calculator? If so, what is the data type of the field you are calculating?
Thanks so much. I tried it and I still get the same 1 as the output result
Try something like this... I'm running this in field calculator and filtering on an ID, but edit at will.
var myid = $feature.COJ_FacilityID var mysum = 0 var myfs = filter(featuresetbyname($datastore,"BogusPumps",['Integer1'],false),"COJ_FacilityID = @myid") if(!IsEmpty(myfs)){ var mysum = ($feature.Integer1/Sum(myfs,'Integer1')) } return mysum
I ran this on the field "Float1" against this data:
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.