<?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 Arcade Data Expression - Drawdown Chart in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-drawdown-chart/m-p/1302728#M8001</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have a dataset that contains repairs and the expected date that those repairs will be completed.&amp;nbsp; I would like to use an Arcade data expression to help add a drawdown chart to a dashboard.&amp;nbsp; &amp;nbsp;The chart will basically show the total number of repairs required and then subtract from that total based on expected completion dates.&amp;nbsp; In other words there may be 500 repairs and 10 of those repairs have a projected completion date of July 1, 2023.&amp;nbsp; So, the total would be 490 repairs remaining and the chart would show the decline from 500 to 490 on that date.&amp;nbsp; This would continue, date by date, until the number of repairs remaining is zero.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My Arcade data expression utilizes the &lt;/SPAN&gt;FeatureSetByPortalItem&lt;SPAN&gt;, &lt;/SPAN&gt;Filter&lt;SPAN&gt;, and &lt;/SPAN&gt;GroupBy&lt;SPAN&gt; functions to gather the relevant features and groups them by completion dates. Then, it iterates over the grouped dates, calculating the running drawdown value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByPortalItem(Portal('https://******.maps.arcgis.com'), 'deaef816ff7448dc8fae43bca1a23418', 0, ['Projected_Completed_Converted'], false);

var filteredFeatures = Filter(fs, "Projected_Completed_Converted &amp;gt; Timestamp '2020-01-01'");

var completionDates = GroupBy(filteredFeatures, 'Projected_Completed_Converted', { name: 'total', expression: '1', statistic: 'COUNT' });

var totalRowCount = Count(filteredFeatures);

var drawdownFS = {
  fields: [
    { name: 'date', type: 'esriFieldTypeDate' },
    { name: 'drawdown', type: 'esriFieldTypeInteger' }
  ],
  features: []
};

var runningDrawdown = totalRowCount;
var drawdownFeatures = [];

for (var i in completionDates) {
  var completionDate = completionDates[i].key;
  var countValue = completionDates[i].total;

  runningDrawdown -= countValue;

  var feature = {
    attributes: {
      'date': completionDate,
      'drawdown': runningDrawdown
    }
  };

  drawdownFeatures.push(feature);
}

drawdownFS.features = drawdownFeatures;

return FeatureSet(drawdownFS);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run in the Arcade playground I get the following error: "&lt;SPAN&gt;Test execution error: Execution error - Cannot access value using a key of this type. Verify test data."&amp;nbsp; I have tried multiple edits to this code, but I have not had success.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;I am still a beginner to this type of thing, so any suggestions would be very much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 24 Jun 2023 15:58:16 GMT</pubDate>
    <dc:creator>AshleyHayes2</dc:creator>
    <dc:date>2023-06-24T15:58:16Z</dc:date>
    <item>
      <title>Arcade Data Expression - Drawdown Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-drawdown-chart/m-p/1302728#M8001</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a dataset that contains repairs and the expected date that those repairs will be completed.&amp;nbsp; I would like to use an Arcade data expression to help add a drawdown chart to a dashboard.&amp;nbsp; &amp;nbsp;The chart will basically show the total number of repairs required and then subtract from that total based on expected completion dates.&amp;nbsp; In other words there may be 500 repairs and 10 of those repairs have a projected completion date of July 1, 2023.&amp;nbsp; So, the total would be 490 repairs remaining and the chart would show the decline from 500 to 490 on that date.&amp;nbsp; This would continue, date by date, until the number of repairs remaining is zero.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My Arcade data expression utilizes the &lt;/SPAN&gt;FeatureSetByPortalItem&lt;SPAN&gt;, &lt;/SPAN&gt;Filter&lt;SPAN&gt;, and &lt;/SPAN&gt;GroupBy&lt;SPAN&gt; functions to gather the relevant features and groups them by completion dates. Then, it iterates over the grouped dates, calculating the running drawdown value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByPortalItem(Portal('https://******.maps.arcgis.com'), 'deaef816ff7448dc8fae43bca1a23418', 0, ['Projected_Completed_Converted'], false);

var filteredFeatures = Filter(fs, "Projected_Completed_Converted &amp;gt; Timestamp '2020-01-01'");

var completionDates = GroupBy(filteredFeatures, 'Projected_Completed_Converted', { name: 'total', expression: '1', statistic: 'COUNT' });

var totalRowCount = Count(filteredFeatures);

var drawdownFS = {
  fields: [
    { name: 'date', type: 'esriFieldTypeDate' },
    { name: 'drawdown', type: 'esriFieldTypeInteger' }
  ],
  features: []
};

var runningDrawdown = totalRowCount;
var drawdownFeatures = [];

for (var i in completionDates) {
  var completionDate = completionDates[i].key;
  var countValue = completionDates[i].total;

  runningDrawdown -= countValue;

  var feature = {
    attributes: {
      'date': completionDate,
      'drawdown': runningDrawdown
    }
  };

  drawdownFeatures.push(feature);
}

drawdownFS.features = drawdownFeatures;

return FeatureSet(drawdownFS);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run in the Arcade playground I get the following error: "&lt;SPAN&gt;Test execution error: Execution error - Cannot access value using a key of this type. Verify test data."&amp;nbsp; I have tried multiple edits to this code, but I have not had success.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;I am still a beginner to this type of thing, so any suggestions would be very much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2023 15:58:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-drawdown-chart/m-p/1302728#M8001</guid>
      <dc:creator>AshleyHayes2</dc:creator>
      <dc:date>2023-06-24T15:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Drawdown Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-drawdown-chart/m-p/1313786#M8192</link>
      <description>&lt;P&gt;Special thanks to&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/116991"&gt;@Shakthi_Bharathi_Murugesan&lt;/a&gt;&amp;nbsp;for her assistance with this data expression at the Esri User Conference!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the working version:&lt;/P&gt;&lt;PRE&gt;var fs = FeatureSetByPortalItem(Portal('https://******.maps.arcgis.com'), 'deaef816ff7448dc8fae43bca1a23418', 0, ['Projected_Completed_Converted'], false);

var filteredFeatures = Filter(fs, "Projected_Completed_Converted &amp;gt; Timestamp '2020-01-01'");

var completionDates = GroupBy(filteredFeatures, 'Projected_Completed_Converted', { name: 'total', expression: '1', statistic: 'COUNT' });


var totalRowCount = Count(filteredFeatures);

var drawdownFS = {
  fields: [
    { name: 'date', type: 'esriFieldTypeDate' },
    { name: 'drawdown', type: 'esriFieldTypeInteger' }
  ],
  features: []
};

var runningDrawdown = totalRowCount;
var drawdownFeatures = [];

for (var i in completionDates) {
  var completionDate = i['Projected_Completed_Converted']
  var countValue = i['total']

  runningDrawdown -= countValue;

  var feature = {
    attributes: {
      'date': completionDate,
      'drawdown': runningDrawdown
    }
  };

  Push(drawdownFeatures,feature);
}

drawdownFS.features = drawdownFeatures;

return FeatureSet(drawdownFS);&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 19:09:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-drawdown-chart/m-p/1313786#M8192</guid>
      <dc:creator>AshleyHayes2</dc:creator>
      <dc:date>2023-07-31T19:09:57Z</dc:date>
    </item>
  </channel>
</rss>

