<?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 Data Expression returns blank from DateDiff method in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-returns-blank-from-datediff-method/m-p/1571194#M10606</link>
    <description>&lt;P&gt;I'm creating an Arcade expression to feed a dashboard list. The expression groups on an ID to find the earliest date, then I want to find the difference between that date and todays date but DateDiff is returning blanks. I know that date formatting is picky in arcade. Its probably a formatting issue but I cannot figure it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code, which successfully returns a featureSet with a 'scheduled_date' and 'today_date' but 'days_remaining' is empty. I've exclude the connection steps since I know I'm successfully pulling in scheduled_date from the source.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Group on area_id and get aggregate values
var groupedRequests = GroupBy(hydrant_requests, ['area_id'], 
    [ 
 {name: 'ScheduledDate', expression: 'schedule_date', statistic: 'MIN'}
     ]
     ); 

var resultFeatures = [];
var feat
var today_date = Today()

// create a feature array which combines the grouped values + a calced field
for (var record in groupedRequests) 
    {
      feat = {
        attributes:
                {
                 'area_id': record['area_id'],
                 'scheduled_date': Number(record['ScheduledDate']),
                 'today_date' : Number(today_date),
                 'days_remaining': DateDiff(Number(record['ScheduledDate']), Number(today_date), 'days')
                }
              }
      
      // Add each feat result to the resultFeatures array 
      Push(resultFeatures, feat); 
     };
    
// Create a dictionary from the feature array
var myDict  = { 
                'fields': [
                    { name: 'area_id', type: 'esriFieldTypeString' },
                    { name: 'scheduled_date', type: 'esriFieldTypeDate' },
                    { name: 'today_date', type: 'esriFieldTypeDate'},
                    { name: 'days_remaining', type: 'esriFieldTypeInteger'} 
                           ],
                'geometryType': '',
                'features': resultFeatures
              };
              
// Convert dictionary to feature set which can be used in the widget
var fs_dict = FeatureSet(Text(myDict));
return fs_dict;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AshneyDaniel_0-1735078704482.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/122399iBAF4F34622325804/image-size/large?v=v2&amp;amp;px=999" role="button" title="AshneyDaniel_0-1735078704482.png" alt="AshneyDaniel_0-1735078704482.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any ideas appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Dec 2024 22:22:15 GMT</pubDate>
    <dc:creator>AshneyDaniel</dc:creator>
    <dc:date>2024-12-24T22:22:15Z</dc:date>
    <item>
      <title>Data Expression returns blank from DateDiff method</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-returns-blank-from-datediff-method/m-p/1571194#M10606</link>
      <description>&lt;P&gt;I'm creating an Arcade expression to feed a dashboard list. The expression groups on an ID to find the earliest date, then I want to find the difference between that date and todays date but DateDiff is returning blanks. I know that date formatting is picky in arcade. Its probably a formatting issue but I cannot figure it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code, which successfully returns a featureSet with a 'scheduled_date' and 'today_date' but 'days_remaining' is empty. I've exclude the connection steps since I know I'm successfully pulling in scheduled_date from the source.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Group on area_id and get aggregate values
var groupedRequests = GroupBy(hydrant_requests, ['area_id'], 
    [ 
 {name: 'ScheduledDate', expression: 'schedule_date', statistic: 'MIN'}
     ]
     ); 

var resultFeatures = [];
var feat
var today_date = Today()

// create a feature array which combines the grouped values + a calced field
for (var record in groupedRequests) 
    {
      feat = {
        attributes:
                {
                 'area_id': record['area_id'],
                 'scheduled_date': Number(record['ScheduledDate']),
                 'today_date' : Number(today_date),
                 'days_remaining': DateDiff(Number(record['ScheduledDate']), Number(today_date), 'days')
                }
              }
      
      // Add each feat result to the resultFeatures array 
      Push(resultFeatures, feat); 
     };
    
// Create a dictionary from the feature array
var myDict  = { 
                'fields': [
                    { name: 'area_id', type: 'esriFieldTypeString' },
                    { name: 'scheduled_date', type: 'esriFieldTypeDate' },
                    { name: 'today_date', type: 'esriFieldTypeDate'},
                    { name: 'days_remaining', type: 'esriFieldTypeInteger'} 
                           ],
                'geometryType': '',
                'features': resultFeatures
              };
              
// Convert dictionary to feature set which can be used in the widget
var fs_dict = FeatureSet(Text(myDict));
return fs_dict;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AshneyDaniel_0-1735078704482.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/122399iBAF4F34622325804/image-size/large?v=v2&amp;amp;px=999" role="button" title="AshneyDaniel_0-1735078704482.png" alt="AshneyDaniel_0-1735078704482.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any ideas appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 22:22:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-returns-blank-from-datediff-method/m-p/1571194#M10606</guid>
      <dc:creator>AshneyDaniel</dc:creator>
      <dc:date>2024-12-24T22:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression returns blank from DateDiff method</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-returns-blank-from-datediff-method/m-p/1571215#M10607</link>
      <description>&lt;P&gt;Wrapping dates in &lt;STRONG&gt;Number()&lt;/STRONG&gt; is a good idea for Data Expressions, but the function &lt;STRONG&gt;DateDiff&lt;/STRONG&gt; should be given two dates. The way you have it written, you're giving it two numbers. Try just taking the number functions out.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;'days_remaining': DateDiff(record['ScheduledDate'], today_date, 'days')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Dec 2024 04:41:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-returns-blank-from-datediff-method/m-p/1571215#M10607</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-12-25T04:41:06Z</dc:date>
    </item>
  </channel>
</rss>

