<?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 Issues with Cartesian product and populating missing dates in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1598591#M444093</link>
    <description>&lt;P&gt;Good Afternoon!&lt;/P&gt;&lt;P&gt;I'm sure I'm doing something silly, but I'm having an issue with my load script for my cartesian product.&lt;/P&gt;&lt;P&gt;I have a set of records which have a quantity, i.e.&lt;/P&gt;&lt;P&gt;Product | Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| Quantity&lt;/P&gt;&lt;P&gt;ProdA&amp;nbsp; &amp;nbsp; &amp;nbsp;| 03/07/2019 | 10&lt;/P&gt;&lt;P&gt;ProdA&amp;nbsp; &amp;nbsp; | 04/07/2019 | 20&lt;/P&gt;&lt;P&gt;ProdA&amp;nbsp; &amp;nbsp; | 08/07/2019 | 30&lt;/P&gt;&lt;P&gt;My script is below, but it's not populating the 'missing' dates that the product doesn't have a transaction for. I'd expect the script to create a record for 05/07/2019, 06/07/2019 and 07/07/2019 with the previous value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone point me in the direction to where I'm going wrong, please?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// ============= Find Min Date and Max Date
MinMaxDate:
Load Min(mrp_date) as MinDate, Max(mrp_date) as MaxDate 
Resident
MRP;
Let vMinDate = num(peek('MinDate', -1, 'MinMaxDate')) - 1;
Let vMaxDate = num(peek('MaxDate', -1, 'MinMaxDate'));
Drop Table MinMaxDate;

// ============= Create cartesian product
CartesianProduct:
// 1) All dates
Load Date(recno()+$(vMinDate)) as mrp_date Autogenerate vMaxDate - vMinDate;
// 2) All products
Left Join (CartesianProduct)
Load distinct mrp_part resident MRP;

CartesianProduct:
LOAD mrp_part Resident MRP;
join(CartesianProduct)
Load Date(recno()+$(vMinDate)) as mrp_date Autogenerate vMaxDate - vMinDate;


// ============= Join Cartesian product onto Data table
Outer Join (MRP) Load * resident CartesianProduct;
Drop Table CartesianProduct;

// ============= 2nd pass through Data table - populate missing combinations
temp:
LOAD *,
if(mrp_part=peek(mrp_part) and mrp_site = peek(mrp_site) and mrp_domain = peek(mrp_domain), RangeSum(mrp_qty, peek(mrp_cumul)),mrp_qty) as mrp_cumul,
ROWNO() as mrp_row;
LOAD 
mrp_weekyear,
mrp_dataset,
"mrp_detail",
"mrp_domain",
"mrp_nbr",
mrp_date,
mrp_line,
mrp_part,
mrp_site,
monthname(mrp_date) as mrp_monthname,
weekname(mrp_date) as mrp_weekname,
year(mrp_date) as mrp_year,
mrp_type,
if(Len(Trim(mrp_qty))=0,0,mrp_qty) as mrp_qty
RESIDENT MRP
ORDER BY mrp_domain, mrp_site, mrp_part, mrp_weekyear, mrp_date ASC;

Drop Table MRP;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2019 11:25:57 GMT</pubDate>
    <dc:creator>Dayna</dc:creator>
    <dc:date>2019-07-03T11:25:57Z</dc:date>
    <item>
      <title>Issues with Cartesian product and populating missing dates</title>
      <link>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1598591#M444093</link>
      <description>&lt;P&gt;Good Afternoon!&lt;/P&gt;&lt;P&gt;I'm sure I'm doing something silly, but I'm having an issue with my load script for my cartesian product.&lt;/P&gt;&lt;P&gt;I have a set of records which have a quantity, i.e.&lt;/P&gt;&lt;P&gt;Product | Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| Quantity&lt;/P&gt;&lt;P&gt;ProdA&amp;nbsp; &amp;nbsp; &amp;nbsp;| 03/07/2019 | 10&lt;/P&gt;&lt;P&gt;ProdA&amp;nbsp; &amp;nbsp; | 04/07/2019 | 20&lt;/P&gt;&lt;P&gt;ProdA&amp;nbsp; &amp;nbsp; | 08/07/2019 | 30&lt;/P&gt;&lt;P&gt;My script is below, but it's not populating the 'missing' dates that the product doesn't have a transaction for. I'd expect the script to create a record for 05/07/2019, 06/07/2019 and 07/07/2019 with the previous value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone point me in the direction to where I'm going wrong, please?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// ============= Find Min Date and Max Date
MinMaxDate:
Load Min(mrp_date) as MinDate, Max(mrp_date) as MaxDate 
Resident
MRP;
Let vMinDate = num(peek('MinDate', -1, 'MinMaxDate')) - 1;
Let vMaxDate = num(peek('MaxDate', -1, 'MinMaxDate'));
Drop Table MinMaxDate;

// ============= Create cartesian product
CartesianProduct:
// 1) All dates
Load Date(recno()+$(vMinDate)) as mrp_date Autogenerate vMaxDate - vMinDate;
// 2) All products
Left Join (CartesianProduct)
Load distinct mrp_part resident MRP;

CartesianProduct:
LOAD mrp_part Resident MRP;
join(CartesianProduct)
Load Date(recno()+$(vMinDate)) as mrp_date Autogenerate vMaxDate - vMinDate;


// ============= Join Cartesian product onto Data table
Outer Join (MRP) Load * resident CartesianProduct;
Drop Table CartesianProduct;

// ============= 2nd pass through Data table - populate missing combinations
temp:
LOAD *,
if(mrp_part=peek(mrp_part) and mrp_site = peek(mrp_site) and mrp_domain = peek(mrp_domain), RangeSum(mrp_qty, peek(mrp_cumul)),mrp_qty) as mrp_cumul,
ROWNO() as mrp_row;
LOAD 
mrp_weekyear,
mrp_dataset,
"mrp_detail",
"mrp_domain",
"mrp_nbr",
mrp_date,
mrp_line,
mrp_part,
mrp_site,
monthname(mrp_date) as mrp_monthname,
weekname(mrp_date) as mrp_weekname,
year(mrp_date) as mrp_year,
mrp_type,
if(Len(Trim(mrp_qty))=0,0,mrp_qty) as mrp_qty
RESIDENT MRP
ORDER BY mrp_domain, mrp_site, mrp_part, mrp_weekyear, mrp_date ASC;

Drop Table MRP;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 11:25:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1598591#M444093</guid>
      <dc:creator>Dayna</dc:creator>
      <dc:date>2019-07-03T11:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Cartesian product and populating missing dates</title>
      <link>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1598675#M444101</link>
      <description>&lt;P&gt;I must admit that I couldn't completely comprehend your example. The cartesian part seems to be doubled in your code. Personally I would probably concatenate (union in sql) the cartesian product to the fact-data, maybe in the following way:&lt;/P&gt;&lt;P&gt;MinMaxDate:&lt;BR /&gt;Load Min(mrp_date) as MinDate, Max(mrp_date) as MaxDate Resident MRP;&lt;BR /&gt;Let vMinDate = num(peek('MinDate', -1, 'MinMaxDate')) - 1;&lt;BR /&gt;Let vMaxDate = num(peek('MaxDate', -1, 'MinMaxDate'));&lt;BR /&gt;Drop Table MinMaxDate;&lt;/P&gt;&lt;P&gt;CartesianProduct:&lt;BR /&gt;Load Date(recno()+$(vMinDate)) as mrp_date Autogenerate vMaxDate - vMinDate;&lt;BR /&gt;Join (CartesianProduct) Load distinct mrp_part resident MRP;&lt;/P&gt;&lt;P&gt;concatenate(MRP) load *, 0 as Quantity, 'not exists' as Source resident CartesianProduct;&lt;BR /&gt;drop table CartesianProduct;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 13:44:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1598675#M444101</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2019-07-03T13:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Cartesian product and populating missing dates</title>
      <link>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1607657#M444854</link>
      <description>&lt;P&gt;Have a look at the following Design Blog post, it is regarding setting up a master calendar, which I believe may do the trick here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.qlik.com/t5/Qlik-Design-Blog/The-Master-Calendar/ba-p/1471527" target="_blank"&gt;https://community.qlik.com/t5/Qlik-Design-Blog/The-Master-Calendar/ba-p/1471527&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There are some other calendar related posts in the Design Blog too, so if this one does not work, search on 'Calendar' and you should find the others to review.&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR /&gt;Brett&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 16:51:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Issues-with-Cartesian-product-and-populating-missing-dates/m-p/1607657#M444854</guid>
      <dc:creator>Brett_Bleess</dc:creator>
      <dc:date>2019-07-30T16:51:34Z</dc:date>
    </item>
  </channel>
</rss>

