<?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 Calculate average time to complete a task in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1622474#M11177</link>
    <description>&lt;P&gt;I am attempting to calculate the average completion time&amp;nbsp;for a group of activities in an indicator element for a dashboard. I have a filtered dataset from our asset management system (Cityworks) in AGOL and have fields that report the start_time/completion_time. I want to calculate the average time it took to complete all the activities in the dataset. I referenced the solution found &lt;A href="https://community.esri.com/t5/arcgis-dashboards-questions/display-average-flight-time-in-indicator/m-p/1423984" target="_blank"&gt;here&lt;/A&gt;, but keep getting errors that I cannot resolve. Here is what I have tested so far, unsuccessfully.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoshThompson_0-1749591647954.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134167iAF42389E4462AF7B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoshThompson_0-1749591647954.png" alt="JoshThompson_0-1749591647954.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I test this within the Dashboard element, I get the following error(s).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoshThompson_1-1749591682997.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134168iC015B61B0070D19B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoshThompson_1-1749591682997.png" alt="JoshThompson_1-1749591682997.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jun 2025 21:45:41 GMT</pubDate>
    <dc:creator>JoshThompson</dc:creator>
    <dc:date>2025-06-10T21:45:41Z</dc:date>
    <item>
      <title>Calculate average time to complete a task</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1622474#M11177</link>
      <description>&lt;P&gt;I am attempting to calculate the average completion time&amp;nbsp;for a group of activities in an indicator element for a dashboard. I have a filtered dataset from our asset management system (Cityworks) in AGOL and have fields that report the start_time/completion_time. I want to calculate the average time it took to complete all the activities in the dataset. I referenced the solution found &lt;A href="https://community.esri.com/t5/arcgis-dashboards-questions/display-average-flight-time-in-indicator/m-p/1423984" target="_blank"&gt;here&lt;/A&gt;, but keep getting errors that I cannot resolve. Here is what I have tested so far, unsuccessfully.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoshThompson_0-1749591647954.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134167iAF42389E4462AF7B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoshThompson_0-1749591647954.png" alt="JoshThompson_0-1749591647954.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I test this within the Dashboard element, I get the following error(s).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoshThompson_1-1749591682997.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134168iC015B61B0070D19B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoshThompson_1-1749591682997.png" alt="JoshThompson_1-1749591682997.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 21:45:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1622474#M11177</guid>
      <dc:creator>JoshThompson</dc:creator>
      <dc:date>2025-06-10T21:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average time to complete a task</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1622606#M11178</link>
      <description>&lt;P&gt;The post you referenced uses that code in a &lt;A href="https://doc.arcgis.com/en/dashboards/latest/get-started/understand-data-sources.htm#ESRI_SECTION1_73D33C15F40846E2B591B870E2AFD6E1" target="_self"&gt;data expression&lt;/A&gt; to create a FeatureSet, which is used in the indicator. The &lt;A href="https://developers.arcgis.com/arcade/profiles/dashboard-data/" target="_self"&gt;profile&lt;/A&gt; for this functionality contains the &lt;A href="https://developers.arcgis.com/arcade/function-reference/bundles/#data-access" target="_self"&gt;Data access bundle&lt;/A&gt;, which includes the Portal and FeatureSet functions. It looks like there's a missing bundle in the documentation, since you can use the&amp;nbsp;FeatureSetByPortalItem function in a data expression also.&lt;/P&gt;&lt;P&gt;However, you're using this code in the advanced formatting section, which doesn't include the Data access bundle in its formatting &lt;A href="https://developers.arcgis.com/arcade/profiles/dashboard-indicator-formatting/" target="_self"&gt;profile&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 13:16:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1622606#M11178</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-06-11T13:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average time to complete a task</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623489#M11200</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;Thank you for the feedback. As an Arcade novice, that did help my overall understanding.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am restarting the process using the advanced formatting section in the Indicator because I continue to get source errors when attempting to call the feature service in a Data Expression.&lt;/DIV&gt;&lt;DIV&gt;I have created a List element that displays each individual activity and the time it took to complete the process using the guidance from this &lt;A title="https://www.esri.com/arcgis-blog/products/ops-dashboard/real-time/displaying-time-spans-with-arcade-in-dashboards" href="https://www.esri.com/arcgis-blog/products/ops-dashboard/real-time/displaying-time-spans-with-arcade-in-dashboards" target="_blank" rel="noopener"&gt;article&lt;/A&gt;&amp;nbsp;and attached the code and screenshot. I wanted to extend that functionality to average those individual completion times in an Indicator using the advanced formatting section. Is this possible using this method?&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 13 Jun 2025 16:28:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623489#M11200</guid>
      <dc:creator>JoshThompson</dc:creator>
      <dc:date>2025-06-13T16:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average time to complete a task</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623501#M11201</link>
      <description>&lt;P&gt;Can you post your code using the &lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633#U1007633" target="_self"&gt;Insert/Edit code sample&lt;/A&gt; button? Trying to decipher code in an image is too difficult, especially when attempting to test your code.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 16:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623501#M11201</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-06-13T16:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average time to complete a task</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623506#M11202</link>
      <description>&lt;P&gt;Here is the code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Calculate how many seconds it took
var dateOpened = $datapoint["DateTimeInit"];
var dateCleared = $datapoint["DateTimeClosed"];
var secondsToRespond = DateDiff(dateCleared, dateOpened, 'seconds');

// Function to format elapsed time
function formatElapsedTime(numSeconds, type) {
    if (IsEmpty(type)) { type = 1 };
    if (TypeOf(numSeconds) != 'Number' || IsEmpty(numSeconds)) { return '' };
    numSeconds = Floor(Abs(numSeconds),0);
    var numMinutes = Floor(numSeconds/60,0);
    var numHours = Floor(numSeconds/(60*60),0);
    var numDays = Floor(numSeconds/(60*60*24),0);
    
    //Type 1 will format the time to use short-hand labels
    if (type == 1) {
        var elapsedTime = When(
            numMinutes &amp;lt; 1, numSeconds + 's',
            numHours &amp;lt; 1, numMinutes + 'm',
            numDays &amp;lt; 1, numHours + 'h ',
            numDays + ' days'
            );
        return elapsedTime;
    }

    //Type 2 will format the time to a clock-format (H:mm:ss)
    if (type == 2) {
        var relativeDate = DateAdd(Date(0,0,0,0,0,0), numSeconds, 'seconds');
        var elapsedTime = When(
            numHours &amp;lt; 1, Text(relativeDate,'mm:ss'),
            numDays &amp;lt; 1, Text(relativeDate,'HH:mm:ss'),
            numDays + ' days ' + Text(relativeDate,'HH:ss')
            );
        return elapsedTime;
    }
}  

var responseTime = formatElapsedTime(secondsToRespond, 1);

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
  attributes: {
    responseTime: responseTime
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 13 Jun 2025 16:47:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623506#M11202</guid>
      <dc:creator>JoshThompson</dc:creator>
      <dc:date>2025-06-13T16:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average time to complete a task</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623533#M11203</link>
      <description>&lt;P&gt;The advanced formatting tool is designed to format individual values (an indicator result or an item in a list), not calculating values from an entire featureset. What you'll need to do write a data expression for the indicator that will calculate that average. You would use your formatting function in the indicator's advanced formatting section. Your data expression would look something like this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
  Portal("yourPortalUrl"),
  "yourItemId",
  0,
  ["DateTimeInit", "DateTimeClosed"],
  false
);

var responseTime = 0;
var counter = 0;

for (var f in fs) {
  var dateOpened = f.DateTimeInit;
  var dateCleared = f.DateTimeClosed;
  if (!IsEmpty(dateOpened) &amp;amp;&amp;amp; !IsEmpty(dateCleared)) {
    responseTime += DateDiff(dateCleared, dateOpened, "seconds");
    counter += 1;
  }
}

return FeatureSet(
  {
    fields: [{ name: "Average", type: "esriFieldTypeInteger" }],
    features: [{ attributes: { Average: Round(responseTime / counter) } }]
  }
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 18:04:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculate-average-time-to-complete-a-task/m-p/1623533#M11203</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-06-13T18:04:30Z</dc:date>
    </item>
  </channel>
</rss>

