Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Script 1 Erroneous

The following script


// ==========================================

Intervals_and_Products: Load ProductID, BeginInterval, EndInterval, Price FROM Prices.txt (ansi, txt, delimiter is ',', embedded labels); Dates_and_Products: Load ProductID, Date, Salesman FROM Transactions.txt (ansi, txt, delimiter is ',', embedded labels); Dates_and_Intervals_and_Products: IntervalMatch (Date, ProductID) Load BeginInterval, EndInterval, ProductID Resident Intervals_and_Products;
// ==========================================

Produces the following structure:

This structure is too complex to evaluate easily. (It would be easy if all joins were Inner Joins, but in QlikView they are not always Inner Joins.) So, the result is that QlikView cannot evaluate the data correctly. Unfortunately, this is not yet well described in the documentation.

Script 2 - Correct
A correct script could be the following:
// ==========================================

Intervals_and_Products: Load ProductID, BeginInterval, EndInterval, Price FROM Prices.txt (ansi, txt, delimiter is ',', embedded labels); Dates_and_Products: Load ProductID, Date, Salesman FROM Transactions.txt (ansi, txt, delimiter is ',', embedded labels); Dates_and_Intervals_and_Products: Inner Join IntervalMatch (Date, ProductID) Load BeginInterval, EndInterval, ProductID Resident Intervals_and_Products;
// ==========================================

This structure QlikView can evaluate, and it is a good solution if an event (Date) only belongs to one interval (per ProductID, of course).

Script 3 - Correct
A solution that always works is the following:
// ==========================================

Intervals_and_Products: Load ProductID as TempProductID, ProductID & '/' & BeginInterval & '/' & EndInterval as ProductIntervalKey, BeginInterval, EndInterval, Price FROM Prices.txt (ansi, txt, delimiter is ',', embedded labels); Dates_and_Products: Load ProductID, ProductID as TempProductID, ProductID & '/' & Date as ProductDateKey, Date, Salesman FROM Transactions.txt (ansi, txt, delimiter is ',', embedded labels); Temp_Dates_and_Intervals_and_Products: IntervalMatch (Date, TempProductID) Load BeginInterval, EndInterval, TempProductID Resident Intervals_and_Products; Dates_and_Intervals_and_Products: Load TempProductID & '/' & BeginInterval & '/' & EndInterval as ProductIntervalKey, TempProductID & '/' & Date as ProductDateKey resident Temp_Dates_and_Intervals_and_Products; Drop Table Temp_Dates_and_Intervals_and_Products; Drop Field TempProductID;
// ==========================================

It is a little more complicated, but the result is a normalized model that always works.

You might also like