You are on page 1of 2

SCRIPTING

PRECEDING LOAD IS ELEGANT


AUG 26, 2014 LEAVE A COMMENT

I love the preceding load feature of Qlikview scripting. It can make complex things simple.
Consider for example, having to parse an arbitrary number of key:value pairs from input like:
Name:Shoes, Size:L, Color:Blue Suede, Stock: 200
Name:Socks, Model:Mens Casual, Stock:0, Color:Black
Name:Pants, Error: No attributes found
We want each key to become a Field populated with its matching value. Heres the entire script
to do just that. A preceding load is a series of chained LOADs that execute from the bottom up
so read the script from the bottom.

And now we can build a chart like this.

Simple. Elegant.
Ill be showing some other cool examples of Preceding Load in my Advanced Scripting session at
the Masters Summit for Qlikview Oct 1.
-Rob
Script suitable for copy/paste

data:
// 4. Generic Load to transpose Key to Field
Generic LOAD RecId, Key, Value
;
// 3. Separate key & value
LOAD
RecId,
subfield(Pair,':',1) as Key,
subfield(Pair,':',2) as Value
;
// 2. Break out each key:value pair
LOAD
RecId,
subfield(Input,',') as Pair
;
// 1. Load the raw Input
LOAD *, RecNo() as RecId INLINE [
Input
Name:Shoes, Size:L, Color:Blue Suede, Stock: 200
Name:Socks, Model:Mens Casual, Stock:0, Color:Black
Name:Pants, Error: No attributes found
] (delimiter is '|')
;

You might also like