Select to view content in your preferred language

Arcade percent total

764
4
Jump to solution
04-16-2024 09:07 AM
Labels (1)
Ed_
by MVP Regular Contributor
MVP Regular Contributor

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)

 

 

Question | Analyze | Visualize
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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

 

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

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)

 

0 Kudos
Ed_
by MVP Regular Contributor
MVP Regular Contributor

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

 

Ed__0-1713285823677.png

 

 

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

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

 

0 Kudos
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Yup that worked like a charm sir cheers 🙂

Question | Analyze | Visualize
0 Kudos