<?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: DQL problem with dates in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/DQL-problem-with-dates/m-p/265740#M1545</link>
    <description>&lt;P&gt;Yes, you cannot access these fields. This is the example of place where DQL's logic is very different (for a reason) the SQL's logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately there is not a proper solution for you problem, but it is indeed valid use case. For now I can offer only a workaround which is safe to use when you have low number of davis problem and events due to initial filtering applied. In the solution I introduce (same as you) fake key to produce full cartesian product between sets of davis problems and bizevents using &lt;EM&gt;&lt;STRONG&gt;join&lt;/STRONG&gt;&lt;/EM&gt; command and filter out not matching pairs (time condition) later:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data
  record(event.name="a", inicio=now()-10m, termino=now()-9m),
  record(event.name="b", inicio=now()-6m, termino=now()-5m),
  record(event.name="c", inicio=now()-3m, termino=now()-2m)
  
| fieldsAdd id=1
| join [
  data
    record(timestamp=now()-11m),
    record(timestamp=now()-9m-30s),
    record(timestamp=now()-9m-20s),
    record(timestamp=now()-7m),
    record(timestamp=now()-2m-30s)
    
    | fieldsAdd id_remoto=1
], on:{left[id]==right[id_remoto]}, kind:leftOuter

| summarize bizcount=countIf ( right.timestamp&amp;gt;inicio and right.timestamp&amp;lt;termino ), by: {event.name}&lt;/LI-CODE&gt;&lt;P&gt;Notes:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Of course my query runs on test data. 1st "problem" spans over 2nd and 3rd "bizevent", 2nd does not have any biz events matching, and 3rd jus one (5th)&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;&lt;STRONG&gt;kind:leftOuter&lt;/STRONG&gt;&lt;/EM&gt; helps in situations when there are no bizevents at all&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1734592130729.png" style="width: 852px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25338i9C6EFA52B5DDFCC5/image-dimensions/852x624?v=v2" width="852" height="624" role="button" title="krzysztof_hoja_0-1734592130729.png" alt="krzysztof_hoja_0-1734592130729.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please note that temporary data structure will be as big as multiplication of number of problems and events, so handle with care &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp; &amp;nbsp;&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>Thu, 19 Dec 2024 07:14:35 GMT</pubDate>
    <dc:creator>krzysztof_hoja</dc:creator>
    <dc:date>2024-12-19T07:14:35Z</dc:date>
    <item>
      <title>DQL problem with dates</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-problem-with-dates/m-p/265557#M1543</link>
      <description>&lt;P&gt;I need your help. I have a query in Dynatrace (DQL) where I have events, and these events have a start date and an end date. I can have multiple events within a time range. These events are retrieved from dt.davis.problems, and now I would like to count sub-events using a join or lookup, but specifically from bizevents, and only those that occurred between the start and end dates of each event.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Event 1&lt;/STRONG&gt;: Start Date : End Date → Here, it should search for how many events in bizevents occurred between the Start Date and End Date.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Event 2&lt;/STRONG&gt;: Start Date : End Date → Here, it should search for how many events in bizevents occurred between the Start Date and End Date.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Event 3&lt;/STRONG&gt;: Start Date : End Date → Here, it should search for how many events in bizevents occurred between the Start Date and End Date.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The start and end dates are distinct and individual for each event, and all these events are within the general timeframe.&lt;BR /&gt;There is also no event ID to match the davis events with the bizevents.&lt;/P&gt;
&lt;P&gt;I had thought of something like this, but it doesn't allow me to access the start and end date information from the main query before performing the lookup.&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;fetch dt.davis.problems
| expand entity_tags
| filter dt.davis.is_duplicate == false 
  and (
	event.name == "xxxx"
    or (contains(entity_tags, "xxxx") and event.name == "Http monitor global outage") 
)
| fields indisponibilidad = (resolved_problem_duration / 1000000000 / 60), event.name ,inicio = event.start , termino = event.end, id = 1
| dedup  inicio, termino, indisponibilidad
| fields id, inicio, termino, indisponibilidad, event.name

| fieldsAdd cant_exito = lookup([
	fetch bizevents
	| filter contains(event.type ,"xxx") and (step == 1001 or step == 1000.20) and event.provider == "xxxxxxx"
    	and timestamp &amp;gt; toTimestamp(inicio) 
		and timestamp &amp;lt; toTimestamp(termino)
	| fieldsAdd id_remoto = 1
	| fields  id_remoto, timestamp, salida = inicio
    ], 
	sourceField: id,
	lookupField: id_remoto)

| fields inicio, termino, indisponibilidad, event.name, cant_exito
| sort inicio&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 18 Dec 2024 07:34:51 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-problem-with-dates/m-p/265557#M1543</guid>
      <dc:creator>Ellery</dc:creator>
      <dc:date>2024-12-18T07:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: DQL problem with dates</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-problem-with-dates/m-p/265740#M1545</link>
      <description>&lt;P&gt;Yes, you cannot access these fields. This is the example of place where DQL's logic is very different (for a reason) the SQL's logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately there is not a proper solution for you problem, but it is indeed valid use case. For now I can offer only a workaround which is safe to use when you have low number of davis problem and events due to initial filtering applied. In the solution I introduce (same as you) fake key to produce full cartesian product between sets of davis problems and bizevents using &lt;EM&gt;&lt;STRONG&gt;join&lt;/STRONG&gt;&lt;/EM&gt; command and filter out not matching pairs (time condition) later:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data
  record(event.name="a", inicio=now()-10m, termino=now()-9m),
  record(event.name="b", inicio=now()-6m, termino=now()-5m),
  record(event.name="c", inicio=now()-3m, termino=now()-2m)
  
| fieldsAdd id=1
| join [
  data
    record(timestamp=now()-11m),
    record(timestamp=now()-9m-30s),
    record(timestamp=now()-9m-20s),
    record(timestamp=now()-7m),
    record(timestamp=now()-2m-30s)
    
    | fieldsAdd id_remoto=1
], on:{left[id]==right[id_remoto]}, kind:leftOuter

| summarize bizcount=countIf ( right.timestamp&amp;gt;inicio and right.timestamp&amp;lt;termino ), by: {event.name}&lt;/LI-CODE&gt;&lt;P&gt;Notes:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Of course my query runs on test data. 1st "problem" spans over 2nd and 3rd "bizevent", 2nd does not have any biz events matching, and 3rd jus one (5th)&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;&lt;STRONG&gt;kind:leftOuter&lt;/STRONG&gt;&lt;/EM&gt; helps in situations when there are no bizevents at all&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1734592130729.png" style="width: 852px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25338i9C6EFA52B5DDFCC5/image-dimensions/852x624?v=v2" width="852" height="624" role="button" title="krzysztof_hoja_0-1734592130729.png" alt="krzysztof_hoja_0-1734592130729.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please note that temporary data structure will be as big as multiplication of number of problems and events, so handle with care &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp; &amp;nbsp;&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>Thu, 19 Dec 2024 07:14:35 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-problem-with-dates/m-p/265740#M1545</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-12-19T07:14:35Z</dc:date>
    </item>
  </channel>
</rss>

