<?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: Problem with date and/or variable and/or WHERE condition in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221855#M500475</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET evaluates the right part before storing (returning a date), then stores. $(max_date) evaluates the contents of the variable, so if value assigned is "01/01/2011" the result of $(max_date) should be 1 divided into 1 divided into 2011 which is equal to 0,000497, this is the value finally stored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the second case, LET evaluates Num(MakeDate()), which returns "40544". $(max_date) evaluates 40544, which is equal to "40544" (the number itself)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you are evaluating twice, when you only want once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SET doesn't evaluate, just stores.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you use SET instead of LET when you create the variable max_date, it will behave as you expect in the first case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Feb 2011 12:15:40 GMT</pubDate>
    <dc:creator>Miguel_Angel_Baeyens</dc:creator>
    <dc:date>2011-02-18T12:15:40Z</dc:date>
    <item>
      <title>Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221854#M500474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;I spent hours on a problem to finally discover that what I though my script will do wasn't right...&lt;/P&gt;&lt;P&gt;I have a table that contains all my data, having a date :&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;TblData:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;MyID, MyDate&lt;BR /&gt;1, 01/01/2010&lt;BR /&gt;2, 31/12/2010&lt;BR /&gt;3, 01/01/2011&lt;BR /&gt;];&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to create a table that contains the lines having the date lower than a specific day.&lt;/P&gt;&lt;P&gt;Here is the code I used :&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;LET max_date = makedate(2011, 1, 1);&lt;BR /&gt;&lt;BR /&gt;TblResult_1:&lt;BR /&gt;LOAD&lt;BR /&gt; MyID AS ResID_1,&lt;BR /&gt; MyDate AS ResDate_1&lt;BR /&gt;RESIDENT TblData&lt;BR /&gt;WHERE num(MyDate) &amp;lt; num($(max_date));&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;(I use the "num( )" function to avoid date format problems)&lt;/P&gt;&lt;P&gt;Unfortunatly, the script returns 0 lines (instead of 2 lines expected) !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After hours of search and tweeks, I found that this code :&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;LET max_date = num(makedate(2011, 1, 1));&lt;BR /&gt;&lt;BR /&gt;TblResult_2:&lt;BR /&gt;LOAD&lt;BR /&gt; MyID AS ResID_2,&lt;BR /&gt; MyDate AS ResDate_2&lt;BR /&gt;RESIDENT TblData&lt;BR /&gt;WHERE num(MyDate) &amp;lt; $(max_date);&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;returns the 2 lines I expected...&lt;/P&gt;&lt;P&gt;The only difference is that the "num( )" function is in the variable declaration, instead of the request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Why is there a difference between the results of my 2 scripts ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:01:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221854#M500474</guid>
      <dc:creator />
      <dc:date>2011-02-18T12:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221855#M500475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET evaluates the right part before storing (returning a date), then stores. $(max_date) evaluates the contents of the variable, so if value assigned is "01/01/2011" the result of $(max_date) should be 1 divided into 1 divided into 2011 which is equal to 0,000497, this is the value finally stored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the second case, LET evaluates Num(MakeDate()), which returns "40544". $(max_date) evaluates 40544, which is equal to "40544" (the number itself)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you are evaluating twice, when you only want once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SET doesn't evaluate, just stores.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you use SET instead of LET when you create the variable max_date, it will behave as you expect in the first case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:15:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221855#M500475</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2011-02-18T12:15:40Z</dc:date>
    </item>
    <item>
      <title>Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221856#M500476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This helps !&lt;/P&gt;&lt;P&gt;But why "LET = makedate(2011, 1, 1)" returns a string instead of a date ?&lt;/P&gt;&lt;P&gt;You say I "evaluate twice" because "$( )" makes an evalution. But I'm forced to use this syntax in the request, right ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:21:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221856#M500476</guid>
      <dc:creator />
      <dc:date>2011-02-18T12:21:20Z</dc:date>
    </item>
    <item>
      <title>Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221857#M500477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;TblData:&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;BR /&gt;MyID, MyDate&lt;BR /&gt;1, 01/01/2010&lt;BR /&gt;2, 31/12/2010 // taking as String, because of MM/DD/YYYY format&lt;BR /&gt;3, 01/01/2011&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;AND&lt;/P&gt;&lt;P&gt;LET max_date = makedate(2011, 1, 1);&lt;BR /&gt;&lt;BR /&gt;TblResult_1:&lt;BR /&gt;LOAD&lt;BR /&gt; MyID AS ResID_1,&lt;BR /&gt; MyDate AS ResDate_1&lt;BR /&gt;RESIDENT TblData&lt;BR /&gt;WHERE num(MyDate) &amp;lt; num($(max_date)); // No need of Num () , simply replace it with&lt;/P&gt;&lt;P&gt;Where MyDate &amp;lt; '$(max_date)'; // because it needs again a string comparison if not Number.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Regards, tresesco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:21:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221857#M500477</guid>
      <dc:creator>tresB</dc:creator>
      <dc:date>2011-02-18T12:21:27Z</dc:date>
    </item>
    <item>
      <title>Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221858#M500478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I always use "num( )" to surround my dates, to avoid date format problems (when I get dates from Excel or from DB, I often have a problem).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanx to you two, I found that I missed single quotes to make my variable a string.&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;LET max_date = makedate(2011, 1, 1);&lt;BR /&gt;...&lt;BR /&gt;WHERE num(MyDate) &amp;lt; num('$(max_date)');&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;(but I still don't understand why it's not a date, but a string)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:28:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221858#M500478</guid>
      <dc:creator />
      <dc:date>2011-02-18T12:28:30Z</dc:date>
    </item>
    <item>
      <title>Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221859#M500479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;nmartin wrote:But why "LET = makedate(2011, 1, 1)" returns a string instead of a date ?&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Any value in QlikView is interpretable as literal or numeric. Since 01/01/2011 is interpretable as a numeric operation, is evaluable, and since LET evaluates before storing, this divides the result of the makedate function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;nmartin wrote:You say I "evaluate twice" because "$( )" makes an evalution. But I'm forced to use this syntax in the request, right ?&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;That's why you need to do a SET instead of a LET, otherwise the reload will fail, because it will look for "max_date" as a field instead of a variable/value.&lt;/P&gt;&lt;P&gt;Hope that makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:43:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221859#M500479</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2011-02-18T12:43:04Z</dc:date>
    </item>
    <item>
      <title>Problem with date and/or variable and/or WHERE condition</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221860#M500480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;nmartin wrote:(but I still don't understand why it's not a date, but a string)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;It was never a string since you used LET. For a string (literal) you should use SET.&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:47:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-date-and-or-variable-and-or-WHERE-condition/m-p/221860#M500480</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2011-02-18T12:47:40Z</dc:date>
    </item>
  </channel>
</rss>

