<?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 time difference between two records in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/256879#M1238</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to calculate the time difference the current record and previous record, until the end of the record.&lt;/P&gt;
&lt;P&gt;example,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sona282_0-1727130396673.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22815i8F8C9D239C63FBE4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sona282_0-1727130396673.png" alt="Sona282_0-1727130396673.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2024 06:29:15 GMT</pubDate>
    <dc:creator>Sona282</dc:creator>
    <dc:date>2024-09-25T06:29:15Z</dc:date>
    <item>
      <title>Calculate time difference between two records</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/256879#M1238</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to calculate the time difference the current record and previous record, until the end of the record.&lt;/P&gt;
&lt;P&gt;example,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sona282_0-1727130396673.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22815i8F8C9D239C63FBE4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sona282_0-1727130396673.png" alt="Sona282_0-1727130396673.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 06:29:15 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/256879#M1238</guid>
      <dc:creator>Sona282</dc:creator>
      <dc:date>2024-09-25T06:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between two records</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/256999#M1239</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;The easiest way to do this is to convert your DateTime values and then subtract the start time from the end time.&lt;/P&gt;&lt;PRE&gt;| fieldsAdd myendtime = toTimestamp(myendtime), mystarttime = toTimestamp(mystarttime)&lt;BR /&gt;| fieldsAdd myduration = myendtime - mystarttime&lt;/PRE&gt;&lt;P&gt;You might need to perform the same subtraction multiple times until the end of the record.&lt;/P&gt;&lt;P&gt;Let me know if this works for you&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 15:34:18 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/256999#M1239</guid>
      <dc:creator>JeanBlanc</dc:creator>
      <dc:date>2024-09-24T15:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between two records</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/257130#M1248</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Window function are not available yet, but it is possible under certain limitations using&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;collectArray&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;, array sorting, and&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;arrayDelta&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;functions and your data set has well defined order:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data 
  record(timestamp=now(), tx="a"),
  record(timestamp=now()+500ms, tx="b"),
  record(timestamp=now()+2s, tx="c"),
  record(timestamp=now()+3s, tx="d"),
  record(timestamp=now()+4s, tx="e"),
  record(timestamp=now()+5s, tx="f"),
  record(timestamp=now()+13s, tx="g"),
  record(timestamp=now()+14s, tx="h"),
  record(timestamp=now()+15s, tx="i"),
  record(timestamp=now()+16s, tx="j")
| sort timestamp asc
| fieldsAdd d = record(t=timestamp, tx)
| summarize d = collectArray(d)
| fieldsAdd d  =arraySort(d, direction:"ascending")
| fieldsAdd dt = arrayDelta(iCollectArray(unixNanosFromTimestamp(d[][t])))
| fields d = record( timestamp=d[][t], dt = duration(dt[], unit:"ns"), tx=d[][tx])
| expand d
| fields timestamp=d[timestamp], dt=d[dt], tx=d[tx]
| sort timestamp asc&lt;/LI-CODE&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;&lt;P&gt;Result looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1727299526155.png" style="width: 845px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22899iA76340C610491F59/image-dimensions/845x1204?v=v2" width="845" height="1204" role="button" title="krzysztof_hoja_0-1727299526155.png" alt="krzysztof_hoja_0-1727299526155.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;max number of records processed using this method is 131072 according to documentation:&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/aggregation-functions#collectArray" target="_blank" rel="noopener noreferrer"&gt;https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/aggregation-functions#collectArray&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 21:25:50 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-time-difference-between-two-records/m-p/257130#M1248</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-09-25T21:25:50Z</dc:date>
    </item>
  </channel>
</rss>

