<?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. :[9SR6] How to generate date intervals from a list of events in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241722#M92115</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I don't see another way than the "previous" / "peek" to make your treatment.&lt;BR /&gt;&lt;BR /&gt;Why did you use 3 Load statement ?&lt;/P&gt;&lt;P&gt;You could not do it in the same LOAD ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;&lt;BR style="margin:0cm 0cm 0pt;" /&gt;interval:&lt;BR /&gt;Load&lt;BR /&gt;id,&lt;BR /&gt;event_date As event_start,&lt;BR /&gt;If(previous(id)= id, previous(event_date), null()) As event_end,&lt;BR style="margin:0cm 0cm 0pt;" /&gt;event&lt;BR style="margin:0cm 0cm 0pt;" /&gt;resident event&lt;BR style="margin:0cm 0cm 0pt;" /&gt;order by id, event_date desc&lt;BR /&gt;;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Mar 2011 09:53:25 GMT</pubDate>
    <dc:creator />
    <dc:date>2011-03-09T09:53:25Z</dc:date>
    <item>
      <title>[9SR6] How to generate date intervals from a list of events</title>
      <link>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241721#M92114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello dear Qliklovers.&lt;/P&gt;&lt;P&gt;I have a question about a typical issue but I haven't found a solution with the search function: I have a table with a list of events, and I want to create the intervals between the events (included or excluded, it's not the question).&lt;/P&gt;&lt;P&gt;In Oracle I can do that with the analytic function LEAD (or LAG) that get the next value for a given key and a given sort. But in Qlikview I haven't found a function that does the trick. I have found a solution with PREVIOUS but very, very ugly.&lt;/P&gt;&lt;P&gt;Here is how I do the trick with Oracle function in the SQL query :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;&lt;BR /&gt;CONNECT TO [...] (...);&lt;BR /&gt;&lt;BR /&gt;event:&lt;BR /&gt;Load&lt;BR /&gt;id, event_date, event;&lt;BR /&gt;SQL&lt;BR /&gt;select 1 "id", to_date('01/01/2011', 'DD/MM/YYYY') "event_date", 'IN' "event" from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 1, to_date('01/02/2011', 'DD/MM/YYYY'), 'OUT' from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 1, to_date('01/03/2011', 'DD/MM/YYYY'), 'IN' from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 2, to_date('01/01/2011', 'DD/MM/YYYY'), 'IN' from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 2, to_date('01/04/2011', 'DD/MM/YYYY'), 'OUT' from DUAL&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;interval:&lt;BR /&gt;Load&lt;BR /&gt;id, event_start, event_end;&lt;BR /&gt;SQL&lt;BR /&gt;select&lt;BR /&gt;"id",&lt;BR /&gt;"event_date" "event_start",&lt;BR /&gt;lead("event_date", 1) over (partition by "id" order by "event_date") "event_end"&lt;BR /&gt;from&lt;BR /&gt;(&lt;BR /&gt;select 1 "id", to_date('01/01/2011', 'DD/MM/YYYY') "event_date", 'IN' "event" from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 1, to_date('01/02/2011', 'DD/MM/YYYY'), 'OUT' from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 1, to_date('01/03/2011', 'DD/MM/YYYY'), 'IN' from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 2, to_date('01/01/2011', 'DD/MM/YYYY'), 'IN' from DUAL&lt;BR /&gt;UNION&lt;BR /&gt;select 2, to_date('01/04/2011', 'DD/MM/YYYY'), 'OUT' from DUAL&lt;BR /&gt;)&lt;BR /&gt;;&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;The result is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;&lt;BR /&gt;id event_start event_end&lt;BR /&gt;1 01/01/2011 01/02/2011&lt;BR /&gt;1 01/02/2011 01/03/2011&lt;BR /&gt;1 01/03/2011&lt;BR /&gt;2 01/01/2011 01/04/2011&lt;BR /&gt;2 01/04/2011&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;To do the same thing with Qlikview I do (I use the previously loaded table event):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;&lt;BR /&gt;event_sorted:&lt;BR /&gt;noconcatenate Load&lt;BR /&gt;id As id2,&lt;BR /&gt;event_date As event_date2,&lt;BR /&gt;event As event2&lt;BR /&gt;resident event&lt;BR /&gt;order by id, event_date desc;&lt;BR /&gt;&lt;BR /&gt;interval2:&lt;BR /&gt;Load&lt;BR /&gt;id2 as id2,&lt;BR /&gt;event_date2 As event_start2,&lt;BR /&gt;If(previous(id2)=id2, previous(event_date2), null()) As event_end2&lt;BR /&gt;resident event_sorted;&lt;BR /&gt;&lt;BR /&gt;interval2_sorted:&lt;BR /&gt;noconcatenate Load&lt;BR /&gt;*&lt;BR /&gt;resident interval2&lt;BR /&gt;order by id2, event_start2;&lt;BR /&gt;&lt;BR /&gt;drop table interval2;&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;And the result is good:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;&lt;BR /&gt;id2 event_start2 event_end2&lt;BR /&gt;1 01/01/2011 01/02/2011&lt;BR /&gt;1 01/02/2011 01/03/2011&lt;BR /&gt;1 01/03/2011&lt;BR /&gt;2 01/01/2011 01/04/2011&lt;BR /&gt;2 01/04/2011&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;But it's so ugly ! I think that a function must exist to replace the desc sort and this expression "If(previous(id2)=id2, previous(event_date2), null())", but I don't know it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your ideas / remarks / comments&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Qlikview version : 9 SR6&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2011 12:15:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241721#M92114</guid>
      <dc:creator>nstefaniuk</dc:creator>
      <dc:date>2011-03-08T12:15:27Z</dc:date>
    </item>
    <item>
      <title>Re. :[9SR6] How to generate date intervals from a list of events</title>
      <link>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241722#M92115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I don't see another way than the "previous" / "peek" to make your treatment.&lt;BR /&gt;&lt;BR /&gt;Why did you use 3 Load statement ?&lt;/P&gt;&lt;P&gt;You could not do it in the same LOAD ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;&lt;BR style="margin:0cm 0cm 0pt;" /&gt;interval:&lt;BR /&gt;Load&lt;BR /&gt;id,&lt;BR /&gt;event_date As event_start,&lt;BR /&gt;If(previous(id)= id, previous(event_date), null()) As event_end,&lt;BR style="margin:0cm 0cm 0pt;" /&gt;event&lt;BR style="margin:0cm 0cm 0pt;" /&gt;resident event&lt;BR style="margin:0cm 0cm 0pt;" /&gt;order by id, event_date desc&lt;BR /&gt;;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Mar 2011 09:53:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241722#M92115</guid>
      <dc:creator />
      <dc:date>2011-03-09T09:53:25Z</dc:date>
    </item>
    <item>
      <title>Re. :[9SR6] How to generate date intervals from a list of events</title>
      <link>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241723#M92116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have done the 2 first steps to show that the events must be sorted desc, and the third was just to see the data sorted in the model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So this solution is the only one and can be done in one step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Mar 2011 10:26:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/9SR6-How-to-generate-date-intervals-from-a-list-of-events/m-p/241723#M92116</guid>
      <dc:creator>nstefaniuk</dc:creator>
      <dc:date>2011-03-09T10:26:35Z</dc:date>
    </item>
  </channel>
</rss>

