# Arcade expression to calculate percentage

1680
4
09-29-2021 06:34 AM
Labels (2)
Occasional Contributor II

Hello,

I would like to calculate the percentage of properties that are multiple occupancy.

There are 3 Layers required to do this

1) Multiple Occupancy (Points)

3) Zones (Polygons)

I have created 2 expressions in the Zones Layer so that in the pop-up they 'count' the number of properties in both point Layers

Can I create another expression in the Zones Layer that will in effect

Multiple Occupancy Count / Address Count * 100

So that I can get a %

This is my arcade but the % returned although does not error is not the correct figure

//count multiple occupancy properties
var hmo = FeatureSetByName(\$map, 'Houses in Multiple Occupation HMO')
var countHMO = Count(Intersects(hmo, \$feature))
return countHMO
var address = FeatureSetByName(\$map,"CAG OldAbdn Sample")
//calculate % of multiple occupancy

Thank you 🙂

1 Solution

Accepted Solutions
MVP Frequent Contributor
1. You need to remove the return statements. If you return from a function, everything after the statement is not executed.
2. Arcade expressions don't know of each other. You cant call \$feature["countHMO"], because that calls a field that does not exist. You have to calculate countHMO & countAddress again and use them for calculating the percentage.
``````//count multiple occupancy properties
var hmo = FeatureSetByName(\$map, 'Houses in Multiple Occupation HMO')
var countHMO = Count(Intersects(hmo, \$feature))
//return countHMO
var address = FeatureSetByName(\$map,"CAG OldAbdn Sample")
//calculate % of multiple occupancy

Have a great day!
Johannes
4 Replies
MVP Frequent Contributor
1. You need to remove the return statements. If you return from a function, everything after the statement is not executed.
2. Arcade expressions don't know of each other. You cant call \$feature["countHMO"], because that calls a field that does not exist. You have to calculate countHMO & countAddress again and use them for calculating the percentage.
``````//count multiple occupancy properties
var hmo = FeatureSetByName(\$map, 'Houses in Multiple Occupation HMO')
var countHMO = Count(Intersects(hmo, \$feature))
//return countHMO
var address = FeatureSetByName(\$map,"CAG OldAbdn Sample")
//calculate % of multiple occupancy

Have a great day!
Johannes
Occasional Contributor II

Thank you @JohannesLindner , that worked perfectly 🙂

I wonder (if I may ask), is it possible/is there any value adding a 'round' statement?

When you test the expression it returns many decimal places

however I can control the appearance through Configure Pop-up > Configure Attributes. I just wondered if you rounded in advance if that would increase performance?

Thanks

MVP Frequent Contributor

I don't know if it increases the performance (although I guess the effect would be minimal in either way), but  you can round:

``return Round((countHMO/countAddress)*100, 2)``

Have a great day!
Johannes
Occasional Contributor II

Cool.  Thanks again for your help, much appreciated.