<?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: Sum of date ranges without overlap in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512088#M191335</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad I got you on the right track &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Nov 2013 07:48:05 GMT</pubDate>
    <dc:creator>teempi</dc:creator>
    <dc:date>2013-11-13T07:48:05Z</dc:date>
    <item>
      <title>Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512083#M191330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm totally new to this community, so please bear with me.&lt;/P&gt;&lt;P&gt;As the end user of a report in the making, I work with a skilled consultant on getting everything right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only big obstacle so far, is the root of the accuracy of my report. The data set looks something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#575757&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;-webkit-right&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;NaN&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;transparent&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;,&amp;quot;verticalAlign&amp;quot;:&amp;quot;baseline&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" style="width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="color: #ffffff; background-color: #6690bc; text-align: center;"&gt;Identifier&lt;/TH&gt;&lt;TH style="color: #ffffff; background-color: #6690bc; text-align: center;"&gt;StartTime&lt;/TH&gt;&lt;TH style="color: #ffffff; background-color: #6690bc; text-align: center;"&gt;EndTime&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;1.04.001&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 16:16:52&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 16:18:43&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;1.04.001&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl67" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 16:17:11&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl67" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 16:18:43&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;1.04.001&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;06.11.2013 17:18:38&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;06.11.2013 17:19:03&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;1.04.001&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 17:39:05&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 17:39:48&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;1.04.001&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 17:39:28&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;&lt;SPAN style="color: #ff0000;"&gt;06.11.2013 17:39:48&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;1.04.001&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;07.11.2013 07:43:55&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;07.11.2013 07:44:04&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;1.04.001&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;07.11.2013 08:19:36&lt;/TD&gt;&lt;TD align="right" class="xl66" style="color: rgb(87, 87, 87); text-align: left; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: baseline;"&gt;07.11.2013 08:22:27&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The desired outcome is something like &lt;SPAN style="font-family: 'courier new', courier;"&gt;Sum(EndTime-StartTime)&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;, but without any overlap!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;If I plainly calculate the duration of each date range and add them up, I'll get 0:07:51. But, since two of these records have ranges that do overlap, this will pollute my statistics. Therefore, any overlapping should not be taken into account, and then the result should be 0:05:59, which is quite a difference.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Does anybody have some suggestions I could bring forward to my consultant?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;My apologies if I explained this poorly!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Knut&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2013 11:23:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512083#M191330</guid>
      <dc:creator />
      <dc:date>2013-11-12T11:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512084#M191331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Knut,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just wrote you a long reply but for some reason it vanished so here we go again &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could add a new field to the data in your script. Let's call it "NewStartTime". Populate this field so that if the "EndTime" on the PREVIOUS row is greater than the "StartTime" on the current row, use EndTime of the last row as the value for "NewStartTime". Otherwise you can use "StartTime" of the current row. So in your example for row 2 you would add&amp;nbsp; "&lt;SPAN style="color: #000000;"&gt;06.11.2013 16:18:43&lt;/SPAN&gt;" as the "NewStartTime" and for row 5 you would add "&lt;SPAN style="color: #000000;"&gt;06.11.2013 17:39:48&lt;/SPAN&gt;" (end times from the previous rows).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way you'll cut off the time range that has already been covered by the previous row. After this you should be able to just sum the intervals without getting overlapping.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know you this got you on the right track &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: oh and I'm assuming your data set is ordered by "Identifier" and "StartTime".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Teemu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2013 12:08:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512084#M191331</guid>
      <dc:creator>teempi</dc:creator>
      <dc:date>2013-11-12T12:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512085#M191332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Teemu, and thanks for your reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This sounds like something that will work for most of the cases. We will give it a try.&lt;/P&gt;&lt;P&gt;However, when I think about it, it will occur that we have a more compound challenge. Take some dummy data again:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Identifier&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;StartTime&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;EndTime&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1.04.001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:00:00&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:30:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1.04.001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:05:00&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:10:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1.04.001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:08:00&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:17:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1.04.001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:28:00&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:35:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1.04.001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:35:00&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06.11.2013 10:36:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case, all the rows but the last one have some overlap. This might be an extreme case, but it is possible that such situations could appear in the raw data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Knut&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2013 12:25:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512085#M191332</guid>
      <dc:creator />
      <dc:date>2013-11-12T12:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512086#M191333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ohh that's right, didn't think of that. You could add a new field for the "EndTime" as well. So let's assume "NewEndTime". You must then create a similar logic for this new field:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the "EndTime" for the current row is less than the "NewStartTime" for the current row, use "NewStartTime" as the value for "NewEndTime" (this basically means the interval for this row becomes 0). Otherwise use "EndTime" directly. I think you must also change the logic for "NewStartTime" so that it compares the original "StartTime" to the "NewEndTime" instead of "EndTime".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sorry if this is getting a bit confusing, I'm just typing out as I think. But I'm pretty sure that by using new fields for the times you can get the calculations working correctly. Some polishing to my logic might be required though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Teemu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2013 12:39:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512086#M191333</guid>
      <dc:creator>teempi</dc:creator>
      <dc:date>2013-11-12T12:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512087#M191334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now we are talking! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tested this on some real data, and so far it looks promising. &lt;/P&gt;&lt;P&gt;We will test it in production, and see how it works there, and get back to you with the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm really happy you could help out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Knut&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2013 13:48:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512087#M191334</guid>
      <dc:creator />
      <dc:date>2013-11-12T13:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512088#M191335</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad I got you on the right track &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 07:48:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512088#M191335</guid>
      <dc:creator>teempi</dc:creator>
      <dc:date>2013-11-13T07:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of date ranges without overlap</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512089#M191336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Teemu,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just thought I'd tell you that your suggestion worked perfectly!&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Knut&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Nov 2013 08:38:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-of-date-ranges-without-overlap/m-p/512089#M191336</guid>
      <dc:creator />
      <dc:date>2013-11-25T08:38:13Z</dc:date>
    </item>
  </channel>
</rss>

