<?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: Calculated field will not return correct value for difference between dates. in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176168#M632848</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What &lt;A href="https://community.qlik.com/qlik-users/15823"&gt;swuehl&lt;/A&gt;‌ said and linked to - dates should be date fields, typically read in using the date#() function. And I would keep the calculation in script rather than the presentation layer as long as these two dates are on the same table. And that's my general philosophy - keep the complication in script &lt;SPAN style="font-size: 12pt;"&gt;&lt;EM&gt;&lt;STRONG&gt;except&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt; for aggregations. Do all your aggregating in the presentation layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Jun 2016 23:52:57 GMT</pubDate>
    <dc:creator>johnw</dc:creator>
    <dc:date>2016-06-22T23:52:57Z</dc:date>
    <item>
      <title>Calculated field will not return correct value for difference between dates.</title>
      <link>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176166#M632846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm having an issue with a calculated date field where I need to return the difference between two dates, a Release Date and Delivery Date. I have scripted it and I am getting a variety of results with the majority not being correct. I have designed it to return the actual value when it is a positive value and I wan it to subtract the delivery date from today if the value is negative. In the case that the number value is 0 I want it to return 0. How should I format the date while pulling it in and should I calculate it via set analysis on the presentation layer? I have listed the script, if anyone could provide some advice on how I can address this it would be truly appreciated. Thank you in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;num&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Date.4.Release&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Date.2.Delivery&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)&amp;lt;=0, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;num&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()-&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Date.2.Delivery&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'#,##0'), &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;num&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Date.4.Release&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Date.2.Delivery&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'#,##0')) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Layover &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jun 2016 21:12:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176166#M632846</guid>
      <dc:creator>ecrobles18</dc:creator>
      <dc:date>2016-06-22T21:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated field will not return correct value for difference between dates.</title>
      <link>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176167#M632847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's important to get the date fields loaded with a numeric representation, see&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/2622"&gt;Get the Dates Right&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/2954"&gt;Why don’t my dates work?&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/2830"&gt;Data Types in QlikView&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jun 2016 21:47:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176167#M632847</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2016-06-22T21:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated field will not return correct value for difference between dates.</title>
      <link>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176168#M632848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What &lt;A href="https://community.qlik.com/qlik-users/15823"&gt;swuehl&lt;/A&gt;‌ said and linked to - dates should be date fields, typically read in using the date#() function. And I would keep the calculation in script rather than the presentation layer as long as these two dates are on the same table. And that's my general philosophy - keep the complication in script &lt;SPAN style="font-size: 12pt;"&gt;&lt;EM&gt;&lt;STRONG&gt;except&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt; for aggregations. Do all your aggregating in the presentation layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jun 2016 23:52:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176168#M632848</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2016-06-22T23:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated field will not return correct value for difference between dates.</title>
      <link>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176169#M632849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure which part of the if statement is giving you incorrect answers (true or false or both), but you mentioned you wanted to see 0 when release - delivery = 0. I think in your today's script, if the difference is 0, it will look for difference between today and delivery. You might want to change it to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If(Date.4.Release-Date.2.Delivery &amp;lt; 0, Today() - Date.2.Delivery, Date.4.Release - Date.2.Delivery) as Layover&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice that I removed that equal (=) sign from the if statement's condition. I also removed the use of Num function as difference of two dates should be a number (i.e. if they are true date fields with dual orientation).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Jun 2016 04:01:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculated-field-will-not-return-correct-value-for-difference/m-p/1176169#M632849</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2016-06-23T04:01:19Z</dc:date>
    </item>
  </channel>
</rss>

