<?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: Cumulative Sum with Arcade in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553125#M10432</link>
    <description>&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;To create a running total for each year, you can use a loop to accumulate totals. Here’s a quick example:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;let runningTotal = 0;
const results = GroupBy(fs, 'dc', {name: "Total Meters", expression: "total_gis_meters", statistic: "SUM"});

results.forEach(row =&amp;gt; {
    runningTotal += row["Total Meters"];
    console.log(`Year: ${row.dc}, Running Total: ${runningTotal}`);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will give you the cumulative sum for each year. If you encounter any issues, feel free to share.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2024 05:49:52 GMT</pubDate>
    <dc:creator>Matrio</dc:creator>
    <dc:date>2024-10-29T05:49:52Z</dc:date>
    <item>
      <title>Cumulative Sum with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1552794#M10427</link>
      <description>&lt;P&gt;Getting stuck on solving this dashboard output in creating a cumulative sum over each year. In this dataset, when I return&amp;nbsp;&lt;SPAN&gt;GroupBy&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;fs&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'dc'&lt;/SPAN&gt;&lt;SPAN&gt;, {&lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"Total Meters"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;expression&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"total_gis_meters"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;statistic&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"SUM"&lt;/SPAN&gt;&lt;SPAN&gt;}), I get the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;dc Total Meters ROW__ID&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="48px"&gt;&lt;SPAN class=""&gt;2020&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="78px"&gt;&lt;SPAN class=""&gt;211211&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="66.1094px"&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="48px"&gt;&lt;SPAN class=""&gt;2021&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="78px"&gt;&lt;SPAN class=""&gt;2811&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="66.1094px"&gt;&lt;SPAN class=""&gt;68005&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="48px"&gt;&lt;SPAN class=""&gt;2022&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="78px"&gt;&lt;SPAN class=""&gt;3123&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="66.1094px"&gt;&lt;SPAN class=""&gt;7520&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="48px"&gt;&lt;SPAN class=""&gt;2023&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="78px"&gt;&lt;SPAN class=""&gt;3405&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="66.1094px"&gt;&lt;SPAN class=""&gt;49435&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="48px"&gt;&lt;SPAN class=""&gt;2024&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="78px"&gt;&lt;SPAN class=""&gt;3346&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="66.1094px"&gt;&lt;SPAN class=""&gt;259655&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do now is creating a running total for each year. I assume I need a loop, but nothing I've tried is working. It shouldn't be this difficult, I wouldn't think.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you for any suggestions!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 14:31:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1552794#M10427</guid>
      <dc:creator>TimWillson</dc:creator>
      <dc:date>2024-10-28T14:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553100#M10431</link>
      <description>&lt;P&gt;You can do a cumulative sum with the right SQL expressions. The most straightforward way is to use a loop with the distinct year values.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get distinct year values
var years = Distinct(fs, 'dc')

// output featureset dict
var out_dict = {
  fields: [
    {name: 'dc', type: 'esriFieldTypeInteger'}, // assuming your year is an integer
    {name: 'year_sum', type: 'esriFieldTypeInteger'},
    {name: 'cum_sum', type: 'esriFieldTypeInteger'}
  ],
  geometryType: '',
  features: []
}

// loop over each year, getting the cumulative count and per-year count, add to output dict
for (var y in years) {
  var yr = y['dc']
  
  Push(
    out_dict['features'],
    { attributes: {
      dc: yr,
      year_sum: Sum(Filter(fs, `dc = ${yr}`), 'total_gis_meters'),
      cum_sum: Sum(Filter(fs, `dc &amp;lt;= ${yr}`), 'total_gis_meters')
    }
  )
}

return FeatureSet(Text(out_dict))&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 29 Oct 2024 01:25:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553100#M10431</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-10-29T01:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553125#M10432</link>
      <description>&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;To create a running total for each year, you can use a loop to accumulate totals. Here’s a quick example:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;let runningTotal = 0;
const results = GroupBy(fs, 'dc', {name: "Total Meters", expression: "total_gis_meters", statistic: "SUM"});

results.forEach(row =&amp;gt; {
    runningTotal += row["Total Meters"];
    console.log(`Year: ${row.dc}, Running Total: ${runningTotal}`);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will give you the cumulative sum for each year. If you encounter any issues, feel free to share.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 05:49:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553125#M10432</guid>
      <dc:creator>Matrio</dc:creator>
      <dc:date>2024-10-29T05:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553224#M10435</link>
      <description>&lt;P&gt;Perfect! Thank you! This has baffled me for a week now!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 12:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/cumulative-sum-with-arcade/m-p/1553224#M10435</guid>
      <dc:creator>TimWillson</dc:creator>
      <dc:date>2024-10-29T12:32:30Z</dc:date>
    </item>
  </channel>
</rss>

