<?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: Count days with date difference in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325354#M410131</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=If(ActualDate = Max(TOTAL &amp;lt;ID&amp;gt; ActualDate), CheckoutDate - ActualDate,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; If(ActualDate = Aggr(NODISTINCT Below(ActualDate), ID, Key), 1, Aggr(NODISTINCT Below(ActualDate), ID, Key)-ActualDate))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/167503_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Jun 2017 15:26:25 GMT</pubDate>
    <dc:creator>sunny_talwar</dc:creator>
    <dc:date>2017-06-20T15:26:25Z</dc:date>
    <item>
      <title>Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325349#M410126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ActualDate&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ChangingLocation&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;CheckoutDate&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;Days&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/30/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Room101&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/7/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;&lt;SPAN style="color: #ff0000;"&gt;1&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;1001&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/30/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Room111&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/7/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;&lt;SPAN style="color: #ff0000;"&gt;1&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/1/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Room123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/7/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;&lt;SPAN style="color: #ff0000;"&gt;3&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/4/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Room141&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/7/2017&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;&lt;SPAN style="color: #ff0000;"&gt;3&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need an expression to get the Days column in Red. I need to find out Days present at each location.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the logic for the expression: If ID = Next Row's ID AND&amp;nbsp; If ActualDate=Next Row's Actual Date then Day=1 OR If ActualDate&amp;lt;Next Row's Actual Date then Days=Next Row's Actual Date - Actual Date; For last Actual Date, it is CheckoutDate - ActualDate that's why Days = 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe it will be a nested if statements with FirstSortedValue and LastSortedValue functions. Thought I will get help from any experts here. Sorry, I am not able to post my actual data here so tried to generate a similar logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 14:31:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325349#M410126</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-20T14:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325350#M410127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How did you get 1 for Room123? Shouldn't it be 3 days?&amp;nbsp; 5/4/2017 - 5/1/2017?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:11:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325350#M410127</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-06-20T15:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325351#M410128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;Whats the logic to calculate the Days ??&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:14:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325351#M410128</guid>
      <dc:creator>avinashelite</dc:creator>
      <dc:date>2017-06-20T15:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325352#M410129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good catch Sunny. Sorry, I got messed up at work multitasking. It should be 5/4/2017 - 5/1/2017 so 3. I will update my original entry. Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:18:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325352#M410129</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-20T15:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325353#M410130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Avinash,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the logic for the expression: If ID = Next Row's ID AND&amp;nbsp; If ActualDate=Next Row's Actual Date then Day=1 OR If ActualDate&amp;lt;Next Row's Actual Date then Days=Next Row's Actual Date - Actual Date; For last Actual Date, it is CheckoutDate - ActualDate that's why Days = 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:20:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325353#M410130</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-20T15:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325354#M410131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=If(ActualDate = Max(TOTAL &amp;lt;ID&amp;gt; ActualDate), CheckoutDate - ActualDate,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; If(ActualDate = Aggr(NODISTINCT Below(ActualDate), ID, Key), 1, Aggr(NODISTINCT Below(ActualDate), ID, Key)-ActualDate))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/167503_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:26:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325354#M410131</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-06-20T15:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325355#M410132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am getting a red underline under the first "Key" letter after ID. Then the result looks like below: I may also have to format the date. Going for lunch...will get back on it later to fix the date format in the SQL script.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/167485_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:40:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325355#M410132</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-20T15:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325356#M410133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Key is a new field created in the script&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Table:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOAD *,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;AutoNumber(ActualDate&amp;amp;ChangingLocation) as Key;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOAD * INLINE [&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, ActualDate, ChangingLocation, CheckoutDate&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1001, 4/30/2017, Room101, 5/7/2017&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1001, 4/30/2017, Room111, 5/7/2017&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1001, 5/1/2017, Room123, 5/7/2017&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1001, 5/4/2017, Room141, 5/7/2017&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;];&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:43:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325356#M410133</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-06-20T15:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325357#M410134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sunny! I am copying my script below and including dimensions and expressions. What do I need to modify? My actual SQL is way too complicated so I modified accordingly just for what we are working on. Please excuse any typos. &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;----&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;Days:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;LOAD *,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;AutoNumber(ActualDate&amp;amp;ChangingLocation) as Key;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;SQL SELECT &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;ba.VisitID,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;ba.ID,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;CAST(ba.CheckoutDateTime as DATE) as CheckoutDate,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;CAST(ba.ServiceDateTime as DATE) as KeyDate,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;loc.LocationID as ChangingLocation,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;loc.DateTime as ActualDateTime,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;CAST(loc.DateTime as DATE) as ActualDate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;FROM tb1 as ba&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;LEFT JOIN tb2 loc&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;ON ba.VisitID=loc.VisitID and loc.LocationID IS NOT NULL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chart Properties:&lt;/P&gt;&lt;P&gt;Dimensions:&lt;/P&gt;&lt;P&gt;1) ID&lt;/P&gt;&lt;P&gt;2) ActualDateTime&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expressions:&lt;/P&gt;&lt;P&gt;1) ActualDate&lt;/P&gt;&lt;P&gt;2) ChangingLocation&lt;/P&gt;&lt;P&gt;3) CheckoutDate&lt;/P&gt;&lt;P&gt;4) =If(ActualDate = Max(TOTAL &amp;lt;ID&amp;gt; ActualDate), CheckoutDate- ActualDate,&lt;/P&gt;&lt;P&gt;&amp;nbsp; If(ActualDate = Aggr(NODISTINCT Below(ActualDate), ID, Key), 1, Aggr(NODISTINCT Below(ActualDate), ID, Key)-ActualDate))&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I reloaded and got the below result. Still something is missing since the third result value needs to be 3 instead of "-".&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="167520" alt="" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/167520_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:52:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325357#M410134</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-20T15:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count days with date difference</title>
      <link>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325358#M410135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had to add "ORDER BY loc.DateTime" at the end on the SQL script. Sunny's code then worked like a charm. Thanks Sunny.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 19:12:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-days-with-date-difference/m-p/1325358#M410135</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-20T19:12:43Z</dc:date>
    </item>
  </channel>
</rss>

