<?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: Arcade expression to calculate a division in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-calculate-a-division/m-p/1224159#M6932</link>
    <description>&lt;P&gt;I'm not quite sure what you're trying to achieve, because&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;sum_ano and sum_perimeter aren't defined in your code&lt;/LI&gt;&lt;LI&gt;assuming Area_ha and Area_km2 area the area values of the same polygon, the result will be 100, as that's the conversion factor between ha and km²&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;But, assuming you want to get the sums of two fields grouped by a third field, and then divide those sums for each group:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load your data
var d = {
    geometryType:"",
    fields:[
        {name:"GroupField", type:"esriFieldTypeInteger"},
        {name:"Field1", type:"esriFieldTypeDouble"},
        {name:"Field2", type:"esriFieldTypeDouble"},
        ],
    features:[]
}
for(var i = 0; i &amp;lt; 20; i++) {
    var f = {attributes: {GroupField: Round(Random()*10, 0), Field1: Random(), Field2: Random()}}
    Push(d.features, f)
}
var fs = Featureset(Text(d))
//return fs


// get the sums grouped by a field
var fs_sums = GroupBy(fs, ["GroupField"], [
    {name: "sum_field_1", expression: "Field1", statistic: "SUM"},
    {name: "sum_field_2", expression: "Field2", statistic: "SUM"},
    ])

// use group by again, grouping by the same field, but using another expression
var fs_quotient = GroupBy(fs_sums, ["GroupField"], [
    {name: "sum_field_1", expression: "sum_field_1", statistic: "SUM"},
    {name: "sum_field_2", expression: "sum_field_2", statistic: "SUM"},
    {name: "quotient", expression: "sum_field_1 / sum_field_2", statistic: "SUM"},
    ])
return fs_quotient&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1666331620354.png" style="width: 490px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/54111i77777AE55B65652F/image-dimensions/490x145?v=v2" width="490" height="145" role="button" title="JohannesLindner_0-1666331620354.png" alt="JohannesLindner_0-1666331620354.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Oct 2022 05:53:55 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-10-21T05:53:55Z</dc:date>
    <item>
      <title>Arcade expression to calculate a division</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-calculate-a-division/m-p/1224138#M6931</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am looking for an arcade expression that groups (Groupby) by a field (ano/year) the sum of two fields (area_ha and area_km2) and that returns a field calculating the division of those sums.&lt;/P&gt;&lt;P&gt;In summary I want to combine two columns of a layer, dividing the sum of each one with each othe.&lt;/P&gt;&lt;P&gt;Fields: Ano (years), Area_ha and Area_km2&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;var p = '&lt;A href="https://www.arcgis.com" target="_blank"&gt;https://www.arcgis.com&lt;/A&gt;'&lt;BR /&gt;var itemId = 'e5f830354f5a4542b5ef6ad63da94d80'&lt;BR /&gt;var fs = FeatureSetByPortalItem(Portal(p), itemId, 0, ['*'], false)&lt;BR /&gt;var GroupBy(fs, ['Ano'],&lt;BR /&gt;[ { name: 'sum_area_ha',&lt;BR /&gt;expression: 'Area_ha',&lt;BR /&gt;statistic: 'SUM' },&lt;BR /&gt;{ name: 'sum_area_km2',&lt;BR /&gt;expression: 'Area_km2',&lt;BR /&gt;statistic: 'SUM' },&lt;BR /&gt;])&lt;BR /&gt;Return GroupBy (sum_ano / sum Perimeter)&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 00:02:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-calculate-a-division/m-p/1224138#M6931</guid>
      <dc:creator>SantiagoAvendaño</dc:creator>
      <dc:date>2022-10-21T00:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to calculate a division</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-calculate-a-division/m-p/1224159#M6932</link>
      <description>&lt;P&gt;I'm not quite sure what you're trying to achieve, because&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;sum_ano and sum_perimeter aren't defined in your code&lt;/LI&gt;&lt;LI&gt;assuming Area_ha and Area_km2 area the area values of the same polygon, the result will be 100, as that's the conversion factor between ha and km²&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;But, assuming you want to get the sums of two fields grouped by a third field, and then divide those sums for each group:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load your data
var d = {
    geometryType:"",
    fields:[
        {name:"GroupField", type:"esriFieldTypeInteger"},
        {name:"Field1", type:"esriFieldTypeDouble"},
        {name:"Field2", type:"esriFieldTypeDouble"},
        ],
    features:[]
}
for(var i = 0; i &amp;lt; 20; i++) {
    var f = {attributes: {GroupField: Round(Random()*10, 0), Field1: Random(), Field2: Random()}}
    Push(d.features, f)
}
var fs = Featureset(Text(d))
//return fs


// get the sums grouped by a field
var fs_sums = GroupBy(fs, ["GroupField"], [
    {name: "sum_field_1", expression: "Field1", statistic: "SUM"},
    {name: "sum_field_2", expression: "Field2", statistic: "SUM"},
    ])

// use group by again, grouping by the same field, but using another expression
var fs_quotient = GroupBy(fs_sums, ["GroupField"], [
    {name: "sum_field_1", expression: "sum_field_1", statistic: "SUM"},
    {name: "sum_field_2", expression: "sum_field_2", statistic: "SUM"},
    {name: "quotient", expression: "sum_field_1 / sum_field_2", statistic: "SUM"},
    ])
return fs_quotient&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1666331620354.png" style="width: 490px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/54111i77777AE55B65652F/image-dimensions/490x145?v=v2" width="490" height="145" role="button" title="JohannesLindner_0-1666331620354.png" alt="JohannesLindner_0-1666331620354.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 05:53:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-calculate-a-division/m-p/1224159#M6932</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-10-21T05:53:55Z</dc:date>
    </item>
  </channel>
</rss>

