<?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: load only last 12 weeks from the QVD using where clause in load script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/load-only-last-12-weeks-from-the-QVD-using-where-clause-in-load/m-p/1666989#M449201</link>
    <description>&lt;LI-CODE lang="css"&gt;Temp:
Load
date(WeekEnd(max(Created_Date),0,6)) as MAX_WeekEndDate
From QVD;

let vMaxWeekEndDate=peek('MAX_WeekEndDate',0,'Temp');
&lt;/LI-CODE&gt;&lt;P&gt;Now you can use this Max date variable to generate Temp dates till last five month to check the Last 13 week Dates using &lt;STRONG&gt;Inweek&lt;/STRONG&gt; function&lt;/P&gt;&lt;LI-CODE lang="css"&gt;Last13Week:
Load date(weekend(max(Dates),0,6)) as Last13WeekDate
where Last13weekFlag=1;
Load *,InWeek(Dates,'$(vMaxWeekEndDate)',-13)*-1 as Last13weekFlag;
Load date(addmonths('$(vMaxWeekEndDate)',-5)+ IterNo()-1) as Dates
AutoGenerate 1
While addmonths('$(vMaxWeekEndDate)',-5)+ IterNo()-1&amp;lt;='$(vMaxWeekEndDate)';

Let vLast13WeekDate = Peek('Last13WeekDate',0,'Last13Week');&lt;/LI-CODE&gt;&lt;P&gt;Now you can use these two variable in where condition while load data from QVD&lt;/P&gt;&lt;LI-CODE lang="css"&gt;Test:
Load
Created_Date,  // date format
attribute1,
attribute2,
attribute3,
metric1,
metric2
from QVD
WHERE Created_Date &amp;gt;='$(vLast13WeekDate)' 
and Created_Date &amp;lt;= '$(vMaxWeekEndDate)';&lt;/LI-CODE&gt;&lt;P&gt;If your Date field format in QVD is not in actual Date format then use something like below. Otherwise above where condition should work.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;WHERE date(date#(Created_Date,'YYYY/MM/DD')) &amp;gt;='$(vLast13WeekDate)' 
and date(date#(Created_Date,'YYYY/MM/DD')) &amp;lt;= '$(vMaxWeekEndDate)';

Note : Date format given in Date# should match with format of Date field in QVD&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jan 2020 12:19:15 GMT</pubDate>
    <dc:creator>Kushal_Chawda</dc:creator>
    <dc:date>2020-01-18T12:19:15Z</dc:date>
    <item>
      <title>load only last 12 weeks from the QVD using where clause in load script</title>
      <link>https://community.qlik.com/t5/QlikView/load-only-last-12-weeks-from-the-QVD-using-where-clause-in-load/m-p/1666959#M449193</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I am trying to load only last 13weeks of data from the QVD which includes lot of data but while loading into the dashboard - I only need to get the last 13 weeks data using the max date value in the field created_date.&lt;/P&gt;&lt;P&gt;From the field Created_Date I have to get the weekend dates using weekend(Created_Date,0,6) - this is what we use to get the weekend date&lt;/P&gt;&lt;P&gt;I have the script something below&lt;/P&gt;&lt;P&gt;//load max weekend date into a temp table and put this into variable&lt;/P&gt;&lt;P&gt;Temp:&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;MAX(WeekEnd(Created_Date,0,6) as MAX_WeekEndDate&lt;/P&gt;&lt;P&gt;From QVD;&lt;/P&gt;&lt;P&gt;let vMaxWeekEndDate=peek(get the value into the variable);&lt;/P&gt;&lt;P&gt;Test:&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;Created_Date,&amp;nbsp; // date format&lt;/P&gt;&lt;P&gt;attribute1,&lt;/P&gt;&lt;P&gt;attribute2,&lt;/P&gt;&lt;P&gt;attribute3,&lt;/P&gt;&lt;P&gt;metric1,&lt;/P&gt;&lt;P&gt;metric2&lt;/P&gt;&lt;P&gt;from QVD&lt;/P&gt;&lt;P&gt;WHERE WeekEnd(Created_Date,0,6) &amp;gt;='vMaxWeekEndDate' //say this returns the 01/18/2020&lt;/P&gt;&lt;P&gt;and WeekEnd(Created_Date,0,6) &amp;lt;=&amp;nbsp;&amp;nbsp; //this is where I got stuck - how do I get the last 13 weekends date here&lt;/P&gt;&lt;P&gt;here last 13th weekend date should be - this should be something in October 2019&lt;/P&gt;&lt;P&gt;could anyone please help - I really appreciate your time - please let me know if this is not clear&lt;/P&gt;&lt;P&gt;thanks a lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2020 01:45:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/load-only-last-12-weeks-from-the-QVD-using-where-clause-in-load/m-p/1666959#M449193</guid>
      <dc:creator>RheaQv12</dc:creator>
      <dc:date>2020-01-18T01:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: load only last 12 weeks from the QVD using where clause in load script</title>
      <link>https://community.qlik.com/t5/QlikView/load-only-last-12-weeks-from-the-QVD-using-where-clause-in-load/m-p/1666989#M449201</link>
      <description>&lt;LI-CODE lang="css"&gt;Temp:
Load
date(WeekEnd(max(Created_Date),0,6)) as MAX_WeekEndDate
From QVD;

let vMaxWeekEndDate=peek('MAX_WeekEndDate',0,'Temp');
&lt;/LI-CODE&gt;&lt;P&gt;Now you can use this Max date variable to generate Temp dates till last five month to check the Last 13 week Dates using &lt;STRONG&gt;Inweek&lt;/STRONG&gt; function&lt;/P&gt;&lt;LI-CODE lang="css"&gt;Last13Week:
Load date(weekend(max(Dates),0,6)) as Last13WeekDate
where Last13weekFlag=1;
Load *,InWeek(Dates,'$(vMaxWeekEndDate)',-13)*-1 as Last13weekFlag;
Load date(addmonths('$(vMaxWeekEndDate)',-5)+ IterNo()-1) as Dates
AutoGenerate 1
While addmonths('$(vMaxWeekEndDate)',-5)+ IterNo()-1&amp;lt;='$(vMaxWeekEndDate)';

Let vLast13WeekDate = Peek('Last13WeekDate',0,'Last13Week');&lt;/LI-CODE&gt;&lt;P&gt;Now you can use these two variable in where condition while load data from QVD&lt;/P&gt;&lt;LI-CODE lang="css"&gt;Test:
Load
Created_Date,  // date format
attribute1,
attribute2,
attribute3,
metric1,
metric2
from QVD
WHERE Created_Date &amp;gt;='$(vLast13WeekDate)' 
and Created_Date &amp;lt;= '$(vMaxWeekEndDate)';&lt;/LI-CODE&gt;&lt;P&gt;If your Date field format in QVD is not in actual Date format then use something like below. Otherwise above where condition should work.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;WHERE date(date#(Created_Date,'YYYY/MM/DD')) &amp;gt;='$(vLast13WeekDate)' 
and date(date#(Created_Date,'YYYY/MM/DD')) &amp;lt;= '$(vMaxWeekEndDate)';

Note : Date format given in Date# should match with format of Date field in QVD&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2020 12:19:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/load-only-last-12-weeks-from-the-QVD-using-where-clause-in-load/m-p/1666989#M449201</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2020-01-18T12:19:15Z</dc:date>
    </item>
  </channel>
</rss>

