<?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: Calculating Difference Between Two Dates using Arcade Expressions in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477623#M9636</link>
    <description>&lt;P&gt;Make sure you have the correct item ID. When I try to open it, I get the message "The item you requested cannot be found. The item may have been deleted or you may have entered an incorrect URL."&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2024 13:15:09 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2024-05-23T13:15:09Z</dc:date>
    <item>
      <title>Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1476430#M9617</link>
      <description>&lt;P&gt;I'm trying to add a new variable to my data set that is the difference between two dates, End and Start Date.&amp;nbsp; I plan on using it in an indicator to show average time to close a WO.&amp;nbsp; I created a new Arcade expression, but am receiving an error with it. Maybe there is a between way to achieve this than using an Arcade Expression.&amp;nbsp; I was able to add this data to the pop-ups, but am having trouble recreating within the dashboard.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var fs = FeatureSetByPortalItem(
    portal,
    '9437842bc29b54b07993a9b6b3d63c0d1"',
    0,
    [
        'InitiateDate',
        'DateWoClosed'
    ],
    false
);
     
var startDate = 'InitiateDate'
var endDate = 'DateWoClosed'
var calcDate = DateDiff(EndDate, start_Date, 'hours')

         
var DiffDate = {
    'fields': [{'name':'calc_date', 'type':'esriFieldTypeDouble'},
               {'name':'start_date', 'type':'esriFieldTypeDate'}
               {'name':'end_date', 'type':'esriFieldTypeDate'}],
    'geometryType': '',
    'features':
    [{'attributes':
     {'start_date': startDate,
     'end_date': endDate,
     'calc_Date': calcDate
     }}]};

return FeatureSet(DiffDate);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 17:47:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1476430#M9617</guid>
      <dc:creator>BNix_TPA</dc:creator>
      <dc:date>2024-05-21T17:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1476470#M9618</link>
      <description>&lt;P&gt;If you trying to calculate the average for all the records in the FeatureSet, you'll have to loop through the collection to get that average.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
    portal,
    '9437842bc29b54b07993a9b6b3d63c0d1"',
    0,
    [
        'InitiateDate',
        'DateWoClosed'
    ],
    false
);
var sumDiff;
for (var f in fs) {
  var startDate = f.InitiateDate
  var endDate = f.DateWoClosed
  sumDiff += DateDiff(EndDate, startDate, 'hours')
}
         
var DiffDate = {
    'fields': [{'name':'calc_date', 'type':'esriFieldTypeDouble'}],
    'geometryType': '',
    'features':
    [{'attributes':
     {
     'calc_Date': sumDiff/Count(fs)
     }}]};

return FeatureSet(DiffDate);&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 21 May 2024 18:33:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1476470#M9618</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-05-21T18:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1476911#M9622</link>
      <description>&lt;P&gt;I don't really need the average calculated for all of the data since I can do this within the indicator itself.&amp;nbsp; I just want to add a field showing the hours to close to the data within the dashboard so I can display this in the indicator.&amp;nbsp; I still want the ability to filter based on other fields in the data too after this field is calculated.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 13:53:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1476911#M9622</guid>
      <dc:creator>BNix_TPA</dc:creator>
      <dc:date>2024-05-22T13:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477212#M9629</link>
      <description>&lt;P&gt;This will create a FeatureSet that contains the DateDiff calculation for each record.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
  portal,
  9437842bc29b54b07993a9b6b3d63c0d1
  0,
  ['*'], //or use the only the fields you want to include
  false
);

var s = Schema(fs);
//return s
Push(s.fields, {'name':'CloseTime', 'alias': 'Close Time', 'type': 'esriFieldTypeDouble'})

var temp_dict = {
  fields: s['fields'],
  geometryType: '',
  features: []
}

for (var f in fs) {
  console(f)
  var attrs = {}
  for (var attr in f) {
    attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
  }
  console(attrs)
  attrs['CloseTime'] = DateDiff(f.DateWoClosed, f.InitiateDate, 'hours')
  Push(
    temp_dict['features'],
    {attributes: attrs}
  )
}
return FeatureSet(Text(temp_dict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 19:30:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477212#M9629</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-05-22T19:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477620#M9635</link>
      <description>&lt;P&gt;Thank you Ken.&amp;nbsp; I inputted this into the data expression and received an initial error.&amp;nbsp; I updated the beginning of the code to look like below, but I'm still receiving an error saying unable to execute.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var p = Portal("https://arcgis.com");
var fs = FeatureSetByPortalItem(
  p,
  "9437842bc29b54b07993a9b6b3d63c0d1",
  0,
  ['*'], //or use the only the fields you want to include
  false
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 13:07:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477620#M9635</guid>
      <dc:creator>BNix_TPA</dc:creator>
      <dc:date>2024-05-23T13:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477623#M9636</link>
      <description>&lt;P&gt;Make sure you have the correct item ID. When I try to open it, I get the message "The item you requested cannot be found. The item may have been deleted or you may have entered an incorrect URL."&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 13:15:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1477623#M9636</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-05-23T13:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1478484#M9658</link>
      <description>&lt;P&gt;Thank you so much for your help!&amp;nbsp; This worked.&amp;nbsp; I realized the issues I was having was due to the item ID and I had the wrong sublayer.&amp;nbsp; I'm pulling in a feature service from Cityworks and assumed it was sublayer 0, but it was actually 2. But it works perfectly, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 16:01:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1478484#M9658</guid>
      <dc:creator>BNix_TPA</dc:creator>
      <dc:date>2024-05-24T16:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Between Two Dates using Arcade Expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1552013#M10423</link>
      <description>&lt;P&gt;Hello again, thank you for you help on this.&amp;nbsp; I'm trying to do a similar thing again as this, but this time I want to calculate the difference between two numbers instead of dates.&amp;nbsp; Do you know how to alter this code to make that work?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 18:44:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-difference-between-two-dates-using/m-p/1552013#M10423</guid>
      <dc:creator>BNix_TPA</dc:creator>
      <dc:date>2024-10-24T18:44:31Z</dc:date>
    </item>
  </channel>
</rss>

