Select to view content in your preferred language

How to get sum of each record within a numerical field dynamically.

145
2
3 weeks ago
Shubhreet
Regular Contributor

Hello,

I have a web map with feature layer connected to survey123. It has a numerical field  'cases' which provides count of HCV cases within each community polygon. I would like to show the polygons based on total cases reported so far via gradient of color. Example, polygon A has 4 survey records with cases value = 0,3,4 and 2 while polygon B has 5 cases values = 4, 1,3,2 and 2. So , total cases within polygon A = 9 while within polygon B = 12. As value of 'cases' keeps getting updating via response through survey123 and so does the total cases value within each polygon must be. For visualization, I want my symbology to dynamically get updated by showing darker color for polygon with higher number of total cases.

How can I write an arcade expression within the web map 'styles' setting to this done?  

0 Kudos
2 Replies
Shubhreet
Regular Contributor

An update to my previously asked question. I started writing the code to iterate through each value within a field using For loop. The code is shown below:

var municipality = $feature.municipality_with_confirmed_new; //variable to get municipality ( or community) name
var cases = $feature.confirmed_new_cases_; //variable to get value of number of confirmed cases within each municipality
var sumcases = 0;
 
for (var i in municipality){
  
  Console(i);
  for (var j in cases) {
    Console(j);
    sumcases += j.cases;
   
  }
}
 
 
In the code above, I am trying to iterate through different municipalities (or communities) one by one via first For loop. Within each municipality I am trying to iterate through the values of 'confirmed new cases' reported to get the total sum of cases using variable 'sumcases'. 
Console(i) function does gives the right number of distinct municipalities ( see below) with confirmed cases but Console(j) function does not gives anything. I guess this is where the problem is and because of which I am not getting the results. 
 
The output of Console(i) is as follow:

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

0 Kudos
Shubhreet
Regular Contributor

Hello,

Could anyone please help me identify as to why '$feature.municipality_with_confirmed_new;' in the code in my previous reply only retrieving the very first municipality which had reported the case and not all the distinct municipalities with cases in the feature layer?   I used Console($feature.municipality_with_confirmed_new;) to find out that it was only one municipality being pulled out. 

0 Kudos