<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I sum an attribute within an Arcade featureset created through intersects? in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197854#M9777</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to build on the example given in "Working with data inside feature sets" found&amp;nbsp;&lt;A href="https://www.esri.com/arcgis-blog/products/mapping/mapping/whats-new-with-arcade-taking-a-stroll-through-featuresets-part-2/"&gt;here&lt;/A&gt; and am having trouble finding a way to sum the DBH_TRUNK values for the tree points that intersect the neighborhoods. I thought I could use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;EM&gt;var trees = FeatureSetByName($map,"Urban Forestry")&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;var countTrees = Count(Intersects(trees,$feature))&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;for (var t in countTrees){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return sum(countTrees,t.DBH_TRUNK)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;but this doesn't work and neither do a few other methods I've tried. How do I access the feature set and field to do this? Thanks.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Jun 2019 16:36:50 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2019-06-24T16:36:50Z</dc:date>
    <item>
      <title>How do I sum an attribute within an Arcade featureset created through intersects?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197854#M9777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to build on the example given in "Working with data inside feature sets" found&amp;nbsp;&lt;A href="https://www.esri.com/arcgis-blog/products/mapping/mapping/whats-new-with-arcade-taking-a-stroll-through-featuresets-part-2/"&gt;here&lt;/A&gt; and am having trouble finding a way to sum the DBH_TRUNK values for the tree points that intersect the neighborhoods. I thought I could use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;EM&gt;var trees = FeatureSetByName($map,"Urban Forestry")&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;var countTrees = Count(Intersects(trees,$feature))&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;for (var t in countTrees){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return sum(countTrees,t.DBH_TRUNK)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;but this doesn't work and neither do a few other methods I've tried. How do I access the feature set and field to do this? Thanks.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jun 2019 16:36:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197854#M9777</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-06-24T16:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum an attribute within an Arcade featureset created through intersects?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197855#M9778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/migrated-users/246313" target="_blank"&gt;Gregory Bacon&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess you can do something like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; intersecting_trees &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Intersects&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;$map&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Urban Forestry"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; $feature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;// var count_trees = Count(intersecting_trees);&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Sum&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;intersecting_trees&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"DBH_TRUNK"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your code you were trying to loop through a count. I you want to use a loop and not the Sum function, you could do something like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; intersecting_trees &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Intersects&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;$map&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Urban Forestry"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; $feature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; sum_dbh &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; tree &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; intersecting_trees&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    sum_dbh &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; tree&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;DBH_TRUNK&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; sum_dbh&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:52:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197855#M9778</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T09:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum an attribute within an Arcade featureset created through intersects?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197856#M9779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. Both of these work for me. I think I was very close to success using your first method in one of my early attempts but I deleted $feature by mistake in Line 1 somehow.&amp;nbsp; With respect to the for loop in method 2, you're assigning a starting value, zero, for the sum_dbh variable and the Add Assign += operator accesses the intersected features and performs 0 + DBH_TRUNK1 + DBH_TRUNK2+...etc, correct?&amp;nbsp; Is either method more efficient than the other? They seem to take the same amount of time to populate the pop-up (3-4 seconds).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2019 16:06:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197856#M9779</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-06-25T16:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum an attribute within an Arcade featureset created through intersects?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197857#M9780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/migrated-users/246313"&gt;Gregory Bacon&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You were close indeed.&amp;nbsp;Only of the problems was looping through a count when that should have been a featureset. You are right about the logic. We start off with a variable sum_dbh which is set to 0 before looping through the features. For each feature the dbh_trunk is added to the running&amp;nbsp;total stored in sum_dbh and that value is returned at the end of the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding performance, both the sum and manually looping through the features could cost the same time as you are experiencing. In theory, it should be less time when less requests are made to the server. This could be&amp;nbsp;done by using a single line:&lt;/P&gt;&lt;PRE class="language-javascript line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Sum&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Intersects&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;$map&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Urban Forestry"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; $feature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"DBH_TRUNK"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure though if you will notice any difference. Another aspect could be to limit the number of fields returned by the&amp;nbsp;FeatureSetByName:&lt;/P&gt;&lt;PRE class="language-javascript line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Sum&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Intersects&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;$map&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Urban Forestry"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"DBH_TRUNK"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; False&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; $feature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"DBH_TRUNK"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(note entirely sure if I use the correct field list)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2019 19:40:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-i-sum-an-attribute-within-an-arcade/m-p/197857#M9780</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2019-06-25T19:40:29Z</dc:date>
    </item>
  </channel>
</rss>

