Tuesday, August 19, 2008

Part 2, comments, loading a .csv

Working with scripts.

It's always useful to know how to add some comments to your scripts. So here are the three ways.

Using REM (end it with a ;)

REM this is a two lined comment
because it needs to end with a semi-colon;

using //

//this is a comment
//so is this

Using /* ... */

/* this is
a longer
comment
the end */

I'm lazy so now I'm just going to base some of this off of this tutorial

So let's load in their nifty .csv file. It's the Country1.csv. Click the Tables Files button on the edit script screen, then browse to the Country1.csv and then you will notice it automagically detects that it is comma delimited so then just hit finish.

Should look like

LOAD Country,
Capital,
[Area(km.sq)],
[Population(mio)],
[Pop. Growth],
Currency,
Inflation,
[Official name of Country]
FROM [C:\Tutorial_English v8\Application\Data Sources\Country1.csv] (ansi, txt, delimiter is ',', embedded labels, msq);

You will notice that this is an absolute path. If you delete this script, and then check the Relative Paths checkbox and rerun the wizard, you will notice it will generate a script like this.

Directory;
LOAD Country,
Capital,
[Area(km.sq)],
[Population(mio)],
[Pop. Growth],
Currency,
Inflation,
[Official name of Country]
FROM Country1.csv (ansi, txt, delimiter is ',', embedded labels, msq);

Notice the Directory statement. A directory statement without a following path is going to search the same dir where your .qvw is saved to. You can also specify a directory to look in by typing

Directory c:\userfiles\data;

Ok lets get tricky, now lets say we wanted to use a variable to load our .csv

let myCSV = '[C:\Tutorial_English v8\Application\Data Sources\Country1.csv]';

LOAD Country,
Capital,
[Area(km.sq)],
[Population(mio)],
[Pop. Growth],
Currency,
Inflation,
[Official name of Country]
FROM $(myCSV) (ansi, txt, delimiter is ',', embedded labels, msq);

That's kindof silly though, but doable.

Ok, so let's say we ran the script of one of those versions. If you are following the tutorial we should addArea(km.sq), Capital, Currency, and Population(mio). So now you can see the real fun of qlikview. For example, you can click on amsterdam and see that it has a population of 15.2 million and uses the Euro. And if you clear your selections (hitting the clear button) then you can click on the 15.2 and it will show you the reverse that the capital with a population of 15.2 is amsterdam. You can also clear all of your selections and then let's say click on the Euro and it will show you all the capitals. Click around, get a feel for how the data is connected. Isn't that marvelous!

No comments: