<?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: Data expression to calculate time difference for Pie Chart in Arcade in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100008#M5116</link>
    <description>&lt;P&gt;What did you have to tweak ?(I can edit my response just so it doesn't confuse anyone who might possibly use it in the future)&lt;/P&gt;&lt;P&gt;As to why your code was wrong, you need to iterate through the initial feature set and append the values into a the dictionary you created (this is done by the for loop populating the 'features' [] list)&lt;/P&gt;&lt;P&gt;The only code I can see without the for loop is using SUM on the entire feature set (SUM is a function which can take a feature set and sum field as arguments).&amp;nbsp; What you tried to do with something like&lt;SPAN&gt;'Patrol Type' : 'PatrolType' just doesn't make sense.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Sep 2021 17:31:37 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2021-09-20T17:31:37Z</dc:date>
    <item>
      <title>Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099559#M5108</link>
      <description>&lt;P&gt;I'm working on creating a pie chart to display the total time by patrol type.&amp;nbsp; I have a startTime field and an endTime field in my feature service.&amp;nbsp; I'm displaying it by PatrolType.&amp;nbsp; I have gotten close but I think I'm getting messed up by the field types for time/minutes, etc. Or maybe somethign else is wrong. I get no results but no errors.&amp;nbsp; &amp;nbsp; I'm on a steep learning curve so examples have gotten me most of the way.&lt;/P&gt;&lt;P&gt;Would you use the DateDiff to get the time or is there another way?&amp;nbsp; I was attempting to see how many minutes each patrol was, and then display the total minutes for each patrol type.&amp;nbsp; And do I then need to then Sum up the elapsed minutes?&lt;/P&gt;&lt;P&gt;var myPortal = '&lt;A href="https://boulder.maps.arcgis.com/" target="_blank" rel="noopener"&gt;https://boulder.maps.arcgis.com/&lt;/A&gt;';&lt;BR /&gt;var patrol = FeatureSetByPortalItem(Portal(myPortal), '2a61f35432e24069bdd1a9102d02f0ba', 0, ["startTime", "endTime", "PatrolType", "created_date"], false)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var Dict = {&lt;BR /&gt;'fields' : [&lt;BR /&gt;{'name' : 'Patrol Type', 'type': 'esriFieldTypeString'},&lt;BR /&gt;{'name' : 'Time Elapse', 'type': 'esriFieldTypeDate'},&lt;BR /&gt;],&lt;BR /&gt;geometryType: "",&lt;BR /&gt;features: [],&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;[{'attributes': {&lt;BR /&gt;'Patrol Type' : 'PatrolType',&lt;BR /&gt;'Time Elapse': DateDiff("endTime", "startTime", 'minutes')&lt;BR /&gt;&lt;BR /&gt;}}&lt;BR /&gt;];&lt;BR /&gt;return FeatureSet(Text(Dict));&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 21:17:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099559#M5108</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-09-17T21:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099627#M5112</link>
      <description>&lt;P&gt;dateDiff() returns a number (i.e. the difference in minutes as a number), swap out your TimeElapse field type to&amp;nbsp;esriFieldTypeDouble&lt;/P&gt;&lt;P&gt;also just to check that you are iterating through the feature set to populate the dictionary and just haven't shared that part of the code?&lt;/P&gt;</description>
      <pubDate>Sat, 18 Sep 2021 16:59:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099627#M5112</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-18T16:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099902#M5113</link>
      <description>&lt;P&gt;Thanks David - I think I had tried the double field type also.&lt;/P&gt;&lt;P&gt;But that is a good point, I am not iterating.&amp;nbsp; that is my entire code and this is what I'm getting for my result.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KendellRyan1_0-1632147047274.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23380i16F4F8466F6A8717/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KendellRyan1_0-1632147047274.png" alt="KendellRyan1_0-1632147047274.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm confused though b/c this is what I was using this as an example to follow, but this does not iterate??&lt;BR /&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/ops-dashboard/announcements/introducing-data-expressions-in-arcgis-dashboards/" target="_blank" rel="noopener"&gt;https://www.esri.com/arcgis-blog/products/ops-dashboard/announcements/introducing-data-expressions-in-arcgis-dashboards/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 17:09:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099902#M5113</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-09-20T17:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099997#M5114</link>
      <description>&lt;P&gt;Unable to test but should be close:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var myPortal = 'https://boulder.maps.arcgis.com/';
var patrol = FeatureSetByPortalItem(Portal(myPortal), '2a61f35432e24069bdd1a9102d02f0ba', 0, ["startTime", "endTime", "PatrolType", "created_date"], false)

var Dict = {
  'fields' : [
  {'name' : 'PatrolType', 'type': 'esriFieldTypeString'},
  {'name' : 'TimeElapse', 'type': 'esriFieldTypeDouble'}],
  geometryType: "",
  features: [],
};

var index = 0

for (var feat in patrol) {
  Dict.features[index] = {
    'attributes': {
      'PatrolType' : feat.PatrolType,
      'TimeElapse': DateDiff(feat.endTime, feat.startTime, 'minutes')
    }}
  index++}

return FeatureSet(Text(Dict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 20:49:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1099997#M5114</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-20T20:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100002#M5115</link>
      <description>&lt;P&gt;Thanks David - minor tweak and that worked great, much appreciated!&amp;nbsp; I'm sure this is a newbie question, but can you tell my why that ESRI example I put the URL for in above didn't iterate?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 17:21:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100002#M5115</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-09-20T17:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100008#M5116</link>
      <description>&lt;P&gt;What did you have to tweak ?(I can edit my response just so it doesn't confuse anyone who might possibly use it in the future)&lt;/P&gt;&lt;P&gt;As to why your code was wrong, you need to iterate through the initial feature set and append the values into a the dictionary you created (this is done by the for loop populating the 'features' [] list)&lt;/P&gt;&lt;P&gt;The only code I can see without the for loop is using SUM on the entire feature set (SUM is a function which can take a feature set and sum field as arguments).&amp;nbsp; What you tried to do with something like&lt;SPAN&gt;'Patrol Type' : 'PatrolType' just doesn't make sense.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 17:31:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100008#M5116</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-20T17:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100012#M5117</link>
      <description>&lt;P&gt;Very helpful, I'm going to try to apply that same logic to a different problem I'm trying to solve, where my looping is not successsful.&lt;BR /&gt;&lt;BR /&gt;Oh, all I did was just change "fs" to "Patrol" to match my variable.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 17:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100012#M5117</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-09-20T17:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100244#M5118</link>
      <description>&lt;P&gt;Ah cool, I've updated my code.&amp;nbsp; Would you be able to mark it as an accepted solution?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 12:26:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100244#M5118</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-21T12:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100285#M5121</link>
      <description>&lt;P&gt;Done! Sorry about that!!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 14:09:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1100285#M5121</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-09-21T14:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Data expression to calculate time difference for Pie Chart in Arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1203603#M6687</link>
      <description>&lt;P&gt;Couldn't figure out why my DateDiff wasn't working. Saw this comment and realised my dictionary field type was set to&amp;nbsp;&lt;EM&gt;esriFieldTypeInteger&lt;/EM&gt; when it should have been &lt;EM&gt;esriFieldTypeDouble.&lt;/EM&gt; Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 05:23:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-calculate-time-difference-for/m-p/1203603#M6687</guid>
      <dc:creator>Gerhard</dc:creator>
      <dc:date>2022-08-17T05:23:31Z</dc:date>
    </item>
  </channel>
</rss>

