<?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 Re: Sum Attribute Expression in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158810#M45200</link>
    <description>&lt;P&gt;When you look at how feature layers are brought into a map and accessed &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/query-feature-service-.htm" target="_blank"&gt;from the REST endpoint&lt;/A&gt;, you'll find that it's building a SQL query to submit to the server / database. Even though what you are doing / writing may not itself be SQL, that doesn't mean it isn't &lt;EM&gt;using &lt;/EM&gt;SQL.&lt;/P&gt;&lt;P&gt;In Arcade, many of the functions that work with data at the "layer" level, rather than on single features, may utilize SQL.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;GroupBy&lt;/LI&gt;&lt;LI&gt;Filter&lt;/LI&gt;&lt;LI&gt;Distinct&lt;/LI&gt;&lt;LI&gt;OrderBy&lt;/LI&gt;&lt;LI&gt;All the statistical expressions (min, max, sum, mean, etc)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;To be clear, you're still writing an Arcade expression. It's just that one of the &lt;EM&gt;parameters&lt;/EM&gt; of the Sum function happens to be string of text representing a SQL expression.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2022 13:09:25 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-03-29T13:09:25Z</dc:date>
    <item>
      <title>Sum Attribute Expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158551#M45181</link>
      <description>&lt;P&gt;Hey All-&lt;/P&gt;&lt;P&gt;Apologize for the Arcade (and coding in general) noob question, but I am trying to figure out how to sum up the results of an attribute expression. Here's the scoop, the attribute expression is a polynomial expression that yields the stormwater benefits in dollars of a tree based on the trunk diameter in an expression popup field called StormwaterBenefits:&lt;/P&gt;&lt;P&gt;var SB = (0.0921*(pow($feature.DBH,2)))+(1.5627*$feature.DBH)-3.2441&lt;/P&gt;&lt;P&gt;No big deal, right? But what I want to do is know the sum total of all trees in the population of around 10,000 trees. Seems like I should be able to just do something simple like the following:&lt;/P&gt;&lt;P&gt;var SumSB = Sum($layer, 'StormwaterBenefits')&lt;/P&gt;&lt;P&gt;return '$'+text (SumSB, '#,###.##')&lt;/P&gt;&lt;P&gt;But Arcade won't accept the attribute expression result name as a valid field name as input to another expression. I feel like I am missing something REALLY obvious here. I have a few workarounds in mind, but I am really bent on figuring this out. Again, very little coding experience, so please speak slowly and use small words!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 19:58:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158551#M45181</guid>
      <dc:creator>Steve_Lane</dc:creator>
      <dc:date>2022-03-28T19:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Attribute Expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158596#M45188</link>
      <description>&lt;P&gt;It's true, you can't reference one expression's output from another. So how do you pass StormwaterBenefits into the Sum function?&lt;/P&gt;&lt;P&gt;If you look at the docs for the &lt;A href="https://developers.arcgis.com/arcade/function-reference/math_functions/#sumfeatures-fieldnameorsqlexpression---number" target="_blank"&gt;&lt;STRONG&gt;Sum&lt;/STRONG&gt;&lt;/A&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/math_functions/#sumfeatures-fieldnameorsqlexpression---number" target="_blank"&gt; function&lt;/A&gt;, you'll see that instead of a field, it can &lt;EM&gt;also &lt;/EM&gt;take a SQL92 expression. That's really what you need here.&lt;/P&gt;&lt;P&gt;Your Arcade expression for StormwaterBenefits,&lt;/P&gt;&lt;PRE&gt;(0.0921 * (pow($feature.DBH, 2))) + (1.5627 * $feature.DBH) - 3.2441&lt;/PRE&gt;&lt;P&gt;convered to SQL would look like this:&lt;/P&gt;&lt;PRE&gt;0.0921 * POWER(DBH, 2) + 1.5627 * DBH - 3.2441&lt;/PRE&gt;&lt;P&gt;Worth noting, your expression will keep to the order of operations, so the parentheses are not necessary, except for the POWER function.&lt;/P&gt;&lt;P&gt;So in order to get the sum of the StormwaterBenefits, your Arcade expression would look like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var SumSB = Sum(
    SB,
    '0.0921 * POWER(DBH, 2) + 1.5627 * DBH - 3.2441'
)

return Text(SumSB, '$#,###.##')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Note here that you can move the currency symbol inside of the formatting string on &lt;STRONG&gt;Text&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Here's a test output from the Arcade Playground's sample layer:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1648502390622.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/37514i5344E1A28F7CA913/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1648502390622.png" alt="jcarlson_0-1648502390622.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 21:20:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158596#M45188</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-28T21:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Attribute Expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158769#M45197</link>
      <description>&lt;P&gt;Josh-&lt;/P&gt;&lt;P&gt;Thanks for the info, this is great! I was actually pretty close on this, but it begs the question, why the need to write it in SQL for the Sum and not just reuse the original Arcade expression? I assume this would violate some syntactical principle I am as yet unaware of...&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 11:59:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158769#M45197</guid>
      <dc:creator>Steve_Lane</dc:creator>
      <dc:date>2022-03-29T11:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Attribute Expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158810#M45200</link>
      <description>&lt;P&gt;When you look at how feature layers are brought into a map and accessed &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/query-feature-service-.htm" target="_blank"&gt;from the REST endpoint&lt;/A&gt;, you'll find that it's building a SQL query to submit to the server / database. Even though what you are doing / writing may not itself be SQL, that doesn't mean it isn't &lt;EM&gt;using &lt;/EM&gt;SQL.&lt;/P&gt;&lt;P&gt;In Arcade, many of the functions that work with data at the "layer" level, rather than on single features, may utilize SQL.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;GroupBy&lt;/LI&gt;&lt;LI&gt;Filter&lt;/LI&gt;&lt;LI&gt;Distinct&lt;/LI&gt;&lt;LI&gt;OrderBy&lt;/LI&gt;&lt;LI&gt;All the statistical expressions (min, max, sum, mean, etc)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;To be clear, you're still writing an Arcade expression. It's just that one of the &lt;EM&gt;parameters&lt;/EM&gt; of the Sum function happens to be string of text representing a SQL expression.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 13:09:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/sum-attribute-expression/m-p/1158810#M45200</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-29T13:09:25Z</dc:date>
    </item>
  </channel>
</rss>

