A QlikView feature that is poorly known and brilliant in its simplicity is the Preceding Load.
If you don’t know what it is, then I strongly suggest that you read this blog post and find out. Because it will help you in your QlikView scripting.
So what is it?
It is a way for you to define successive transformations and filters so that you can load a table in one pass but still have several transformation steps. Basically it is a Load statement that loads from the Load/SELECT statement below.
Example: you have a database where your dates are stored as strings and you want to use the QlikView date functions to interpret the strings. But the QlikView date functions are not available in the SELECT statement. The solution is to put a Load statement in front of the SELECT statement: (Note the absence of “From” or “Resident”.)
Load Date#(OrderDate,’YYYYMMDD’) as OrderDate; SQL SELECT OrderDate FROM … ;
What happens then is that the SELECT statement is evaluated first, and the result is piped into the Load statement that does the date interpretation. The fact that the SELECT statement is evaluated before the Load, is at first glance confusing, but it is not so strange. If you read a Preceding Load as
Load From ( Select From ( DB_TABLE ) )
then it becomes clearer. Compare it with nested functions: How would you evaluate “Round( Exp( x ) )”. You would of course evaluate the Exp() function first and then the Round() function. That is, you evaluate it from right to left.
The reason is that the Exp() function is closest to the source data, and therefore should be evaluated first. It’s the same with the Preceding Load: The SELECT is closest to the source data and should therefore be evaluated first. In both cases, you can look at it as a transformation that has an input and an output and to do it correctly, you need to start with the part of the transformation closest to the input.
Any number of Loads can be “nested” this way. QlikView will start from the bottom and pipe record by record to the closest preceding Load, then to the next, etc. And it is almost alwaysfaster than running a second pass through the same table.
With preceding Load, you don’t need to have the same calculation in several places. For instance, instead of writing
where the same calculation is made for both Age and ReferenceDate, I would in real life define my ReferenceDate only once and then use it in the Age function in a Preceding Load:
Assuming that the fields ID, Name, Amount exist in your QVD.qvd, you need to include either the field names or an asterisk (to call all fields) in the first (bottom) load, then the preceding (next) load will pull the already loaded fields and use those.
what I provided you is a guess as I don't know what exact fields you are pulling from the QVD and what your objective is. If all you are trying to do is create a composite key, you don't need a preceding load. Here's a rework of the syntax from above. But, what are you actually trying to do? Learn how to use a preceding load or create a composite key?
LOAD // this gets evaluated second and loads all the below field.
uniqkey,
ID,
Name,
Amount
;
LOAD // so this gets evaluated or compiled first.
*, // loads all the fields
ID &' | '& Name as uniqkey // creates uniqkey.
FROM QVD.qvd (qvd);
1)is my understanding above correct.
2) when qlikview completes compiling or reloading script. does it do compilation twice first to get all the field in memory, do calculation on uniqkey. and then do it again to display it for dashboard.
Thanks Steve, very well explained. I am doing composite key in my code because i am trying to find uniq method to display data on 1:1 level. and then merge new data with old master data with update and append.
can the uniqkey i created used in concatenation with where exist clause. Below gives me field not found error and the source of it is coming from where exist clause.
So i am taking aproach of creating new qvd with composite key being calculated and then storing it into new qvd. however I am finding an unusual problem. i wonder if this is some kind of bug.
updatedata:
LOAD
uniqkey,
ID,
Name,
amount,
ID &' | '& Name as uniqkey
FROM NEW_QVD.qvd (qvd);
store updatedata into new_updatedata.qvd;
MasterData:
LOAD
uniqkey,
ID,
Name,
amount,
ID &' | '& Name as uniqkey
FROM MASTER_QVD.qvd (qvd);
store MasterData into new_masterdata.qvd;
When I do reload the first table store works, the second gives me table not found error. If I switch the tables it will give me error on the second one again.