<?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 Dashboard Pie Chart Data Expression using Date Ranges in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535602#M61368</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am very new to creating Dashboards and am having trouble writing the correct script for what I need. I need a pie chart to represent the features that have an expiration date (E_Date) within the ranges (categories): the next 30 days, the next 31-60 days, the next 61 to 90 days, and the next 90+ days. I have written a script that accurately pushes out an array of the data. But, when I go to select the data expression layer, it says "Unable to Execute Arcade script" and I cannot move forward with the pie chart. Below is the script I have so far. Any advice is much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var fs = FeatureSetByPortalItem(&lt;BR /&gt;Portal('&lt;A href="https://gisportal.xyz.com/portal" target="_blank" rel="noopener"&gt;https://gisportal.xyz.com/portal&lt;/A&gt;'),&lt;BR /&gt;'2917513692574002bfec1932cef87080',&lt;BR /&gt;13,&lt;BR /&gt;['E_DATE', 'LEASE_STAT'],&lt;BR /&gt;false&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;var currentDate = Date();&lt;/P&gt;&lt;P&gt;var within30Days = 0;&lt;BR /&gt;var within31to60Days = 0;&lt;BR /&gt;var within61to90Days = 0;&lt;BR /&gt;var moreThan90Days = 0;&lt;/P&gt;&lt;P&gt;for (var currentFeature in fs) {&lt;BR /&gt;if (HasKey(currentFeature, 'E_DATE') &amp;amp;&amp;amp; currentFeature.E_DATE != null) {&lt;BR /&gt;var expDate = Date(currentFeature.E_DATE);&lt;/P&gt;&lt;P&gt;if (expDate != null &amp;amp;&amp;amp; expDate != 'Invalid Date') {&lt;BR /&gt;&lt;BR /&gt;var daysDiff = DateDiff(expDate, currentDate, 'days');&lt;BR /&gt;&lt;BR /&gt;if (daysDiff &amp;gt;= 0 &amp;amp;&amp;amp; daysDiff &amp;lt;= 30) {&lt;BR /&gt;within30Days += 1;&lt;BR /&gt;} else if (daysDiff &amp;gt; 30 &amp;amp;&amp;amp; daysDiff &amp;lt;= 60) {&lt;BR /&gt;within31to60Days += 1;&lt;BR /&gt;} else if (daysDiff &amp;gt; 60 &amp;amp;&amp;amp; daysDiff &amp;lt;= 90) {&lt;BR /&gt;within61to90Days += 1;&lt;BR /&gt;} else if (daysDiff &amp;gt; 90) {&lt;BR /&gt;moreThan90Days += 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var results = [&lt;BR /&gt;{ "Category": "Within 30 Days", "Count": within30Days },&lt;BR /&gt;{ "Category": "31 to 60 Days", "Count": within31to60Days },&lt;BR /&gt;{ "Category": "61 to 90 Days", "Count": within61to90Days },&lt;BR /&gt;{ "Category": "More than 90 Days", "Count": moreThan90Days }&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;return results;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Sep 2024 17:55:33 GMT</pubDate>
    <dc:creator>LaineMcGannon</dc:creator>
    <dc:date>2024-09-05T17:55:33Z</dc:date>
    <item>
      <title>Dashboard Pie Chart Data Expression using Date Ranges</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535602#M61368</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am very new to creating Dashboards and am having trouble writing the correct script for what I need. I need a pie chart to represent the features that have an expiration date (E_Date) within the ranges (categories): the next 30 days, the next 31-60 days, the next 61 to 90 days, and the next 90+ days. I have written a script that accurately pushes out an array of the data. But, when I go to select the data expression layer, it says "Unable to Execute Arcade script" and I cannot move forward with the pie chart. Below is the script I have so far. Any advice is much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var fs = FeatureSetByPortalItem(&lt;BR /&gt;Portal('&lt;A href="https://gisportal.xyz.com/portal" target="_blank" rel="noopener"&gt;https://gisportal.xyz.com/portal&lt;/A&gt;'),&lt;BR /&gt;'2917513692574002bfec1932cef87080',&lt;BR /&gt;13,&lt;BR /&gt;['E_DATE', 'LEASE_STAT'],&lt;BR /&gt;false&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;var currentDate = Date();&lt;/P&gt;&lt;P&gt;var within30Days = 0;&lt;BR /&gt;var within31to60Days = 0;&lt;BR /&gt;var within61to90Days = 0;&lt;BR /&gt;var moreThan90Days = 0;&lt;/P&gt;&lt;P&gt;for (var currentFeature in fs) {&lt;BR /&gt;if (HasKey(currentFeature, 'E_DATE') &amp;amp;&amp;amp; currentFeature.E_DATE != null) {&lt;BR /&gt;var expDate = Date(currentFeature.E_DATE);&lt;/P&gt;&lt;P&gt;if (expDate != null &amp;amp;&amp;amp; expDate != 'Invalid Date') {&lt;BR /&gt;&lt;BR /&gt;var daysDiff = DateDiff(expDate, currentDate, 'days');&lt;BR /&gt;&lt;BR /&gt;if (daysDiff &amp;gt;= 0 &amp;amp;&amp;amp; daysDiff &amp;lt;= 30) {&lt;BR /&gt;within30Days += 1;&lt;BR /&gt;} else if (daysDiff &amp;gt; 30 &amp;amp;&amp;amp; daysDiff &amp;lt;= 60) {&lt;BR /&gt;within31to60Days += 1;&lt;BR /&gt;} else if (daysDiff &amp;gt; 60 &amp;amp;&amp;amp; daysDiff &amp;lt;= 90) {&lt;BR /&gt;within61to90Days += 1;&lt;BR /&gt;} else if (daysDiff &amp;gt; 90) {&lt;BR /&gt;moreThan90Days += 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var results = [&lt;BR /&gt;{ "Category": "Within 30 Days", "Count": within30Days },&lt;BR /&gt;{ "Category": "31 to 60 Days", "Count": within31to60Days },&lt;BR /&gt;{ "Category": "61 to 90 Days", "Count": within61to90Days },&lt;BR /&gt;{ "Category": "More than 90 Days", "Count": moreThan90Days }&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;return results;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 17:55:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535602#M61368</guid>
      <dc:creator>LaineMcGannon</dc:creator>
      <dc:date>2024-09-05T17:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Pie Chart Data Expression using Date Ranges</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535637#M61371</link>
      <description>&lt;P&gt;Something you always have to remember when creating a Data Expression is that it has to return a FeatureSet. You'll have to take the extra steps to do that like this, replacing your last line with this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var Dict = {
    'fields': [
      {'name': 'Category', 'type': 'esriFieldTypeString'},
      {'name': 'Count', 'type': 'esriFieldTypeInteger'}],
    'geometryType': '',   
    'features': []};

for (var i in results){
  Dict.features[i] = {
    'attributes': {
      'Category':results[i].Category,
      'Count': results[i].Count
    }
  }
}

return FeatureSet(Dict)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 18:49:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535637#M61371</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-09-05T18:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Pie Chart Data Expression using Date Ranges</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535645#M61373</link>
      <description>&lt;P&gt;KenBuja,&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off, thank you so much for your very quick response!&amp;nbsp;&lt;/P&gt;&lt;P&gt;And, thank you for such a great solution! My feature set functioned properly for the pie chart. I appreciate your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 19:32:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/dashboard-pie-chart-data-expression-using-date/m-p/1535645#M61373</guid>
      <dc:creator>LaineMcGannon</dc:creator>
      <dc:date>2024-09-05T19:32:17Z</dc:date>
    </item>
  </channel>
</rss>

