Based on the sample data below I am trying to calculate the percentage
(number / sum of all numbers) * 100
I go to calculate field and create a new field and enter the following, however I keep getting `100%` for each data point. What am I doing wrong with the expression?
var IBPL_Total = sum($feature.data)
var IBPL_PctTotal = ($feature.data/ IBPL_Total)*100
return IBPL_PctTotal
Sample data:
data = (1, 2, 3, 4, 5, 6, 7, 8, 10)
Solved! Go to Solution.
Ooops, I tested it on a popup, not the field calculator. You have to get the layer from the $datastore variable, not the $layer variable.
var fs = FeatureSetByName($datastore,'your layer name')
return $feature.disability_ACSHHDIS/Sum(fs, 'disability_ACSHHDIS') * 100
You're just getting the sum of that single feature in line 1, so its percentage would always be 100%. You have to get the sum of all the features in the dataset to calculate the percentage
return $feature.data/Sum($layer, 'data') * 100)
Hi Ken, hope all is well and thank you for the quick response
So based on the original feature class which has multiple columns, the following is what I wrote but I am getting null values.
return $feature.disability_ACSHHDIS/Sum($feature, 'disability_ACSHHDIS') * 100
Ooops, I tested it on a popup, not the field calculator. You have to get the layer from the $datastore variable, not the $layer variable.
var fs = FeatureSetByName($datastore,'your layer name')
return $feature.disability_ACSHHDIS/Sum(fs, 'disability_ACSHHDIS') * 100
Yup that worked like a charm sir cheers 🙂