Sei sulla pagina 1di 88

Qlikview Developer

Copyright 2013 Accenture All Rights Reserved.

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING
MANIPULATION
AND MATHEMATICAL
Copyright
2013 Accenture
All Rights Reserved.
Copyright
2013 Accenture All Rights Reserved.
FUNCATIONS--------

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
2
PM

03:00
PM
03:30
PM

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
Introduction of Qlikview Script
MODEL----------------------------------------------- TEA BREAK
/
Connect
to the data sources
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
3
PM

03:00
PM
03:30
PM

BASIC OF QLIKVIEW SCRIPTING


> 1) Introduction of Qlikview Script
What type of database does QlikView require to work?
The straight answer to this question is, simply, that QlikView does not
necessarily requires a specific database or Data Warehouse (DWH) to pull
data from. It could benefit from using a DWH, but it is not required.
However, the data must reside somewhere, in order to be able to pull it into
QlikView, visualize it, discover patterns in it, and build all kinds of charts with it.
That somewhere can be almost any standard database, flat file
(for example, .xls or .csv), web page, and so on, or even any combination of the
above.
This data can be stored and managed in a wide range of different systems.
Therefore, it requires different methods for extraction.
Those different methods are for (ETL)
EXTRACTION >> TRANSFORMATION >> LOAD data in Qlikview
And combination of those methods is called

Script

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Qlikview
4

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources
There are many different Database Management Systems (DBMS)
We can, for our purposes, group them into three different categories:
Those that provide connectivity via ODBC/OLE DB drivers
Those that use proprietary systems with no standard connectivity.
Those that are not necessarily DBMSs, but rather have tables stored in plain
files, such as Excel, CSV, TXT, XML, and the like.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)
QlikView can load and interpret the following types of data:

Now
Andthe
theQuestion
answer isis

The result of a database query, made by SQL via OLE DB/ODBC

Any type of character-delimited text files e.g., Comma Separated files

Fixed field value position format files

Excel files in (.xls/.xlsx) format

XML tables

HTML tables

QlikView Data (QVD) files

Previously created QlikView files ( also called Binary load)

Custom data sources (eg. Web services) via a .dll interface

QVX (QlikView Data Exchange)

SCRIPT EDITOR

HOW ?

So Lets explore SCRIPT EDITOR

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)
How to open Script Editor?
STEP 1: Open Qlikview and
create new document and
save it.
STEP 2: Then File >> Edit
Scripts
Or
Ctrl + E
Or
STEP 2: Click on Edit script
icon

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)

dit Script Tool pane:

ool pane has four tab pages containing functions for script generation:
ata, Functions, Variables and Settings.

Tab: Within the Data tab, there are three grouping sections giving you
the control and functionality for bringing data into the QlikView document.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)

base grouping
ommands in the Database group are used to create a connection to a database
elect fields from a data source.

DB : (Object Linking and Embedding Database)


Select this alternative to access databases through OLE DB

: (Open Database Connectivity)


Select this alternative if you wish to access databases thru an ODBC driver
32 Bit : Forces the ODBC/OLE DB connect statement to a 32-bit provider.

ect : Use this button to open the Data Link Properties dialog box
o select an OLE DB or ODBC data source and generate the appropriate connect
statement in load script

t : Once you have established the data connection,


click on this button to open the create select statement dialog box.
Then you will be able to specify fields and tables from the chosen
data sources, and generate the appropriate SELECT statement.
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)

rom Files grouping


mmands in the Data from Files group are used to generating the LOAD script statements
d data from the files

e Paths :
nable this option if the data location is relative to or along the same path as
rrent working directory. Otherwise, it will default to absolute or the alternative path for sta
ated in the scripts.

P:
Mark this check box for the ability to select files from an ftp file server
you request Table Files, QlikView Files or Include script statements.

Files . :
Launches the Open Local Files dialog box listing various test file formats including
oft Excel (.xls, xlsx) and QlikView Data (.qvd) files. Selecting one or several files and pressi
nerate one or several LOAD statements based on the options selected in the wizard.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

10

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)

om Files grouping (Contd..)

w File :
on the this button to open the Open QlikView File dialog box listing QlikView files (*.qvw).
ng a file and pressing OK will generate a binary statement.
ne binary statement is allowed in a QlikView load script and
be the first statement in the load script

es :
ns the Table Files Wizard: Source dialog box to enter a URL as a source for your data table.

ata :
ns the Files Wizard on the Source page where you can load the contents of an already load

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

11

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)
Function Tab:
The commands on this tab are used for generating QlikView functions to be used
within the script statements
Function Category:
Lists the categories into which functions are grouped e.g., Date and Time, or
String etc.
Function Name:
Contains a list of QlikView standard script functions. The list can be narrowed
down by first selecting a category in the Function Category list
Paste:
Click on this button once you have selected the function you need, this function
will then be entered in the script at the current cursor position in the script
dialog window

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

12

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)
Variable Tab:
The Variables tab contains controls for pasting syntax relating to QlikView
variables.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

13

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)
Settings Tab:
The Settings tab contains two groupings, Script Privileges and Settings, that are
used to grant certain rights and settings in the load script.
Script Privileges grouping:
Enables the script to Open Databases in Read and Write mode and/or Execute
External programs.
Settings grouping :
The Scramble Connect User Credentials option will scramble the database user
and password in the connect statements of your script.
This is recommended feature and should only be disabled on the rare occasion
when you need to see the database login for script errors or similar situations

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

14

BASIC OF QLIKVIEW SCRIPTING


> 2) Connect to the data sources (Contd..)
Connect Statement:
The CONNECT statement is used to establish a connection to a database thru
ODBC or OLE DB interface.

Lets create

Once this connection is established, it is used until a new CONNECT is defined.


Multiple CONNECT statements can be defined in a QlikView load script,
But only one database connection can be open at any time.
If the CONNECT statements is generated by the provided wizard any user ID and
password provided will be generated with the scrambled xuserid/xpassword
syntax

one

Qlikview Demo
application

Some examples of Connect Statements


ODBC CONNECT to [SQLDATA; database = SQL1] (UserId is sa, Password is admin)
ODBC CONNECT TO [MS Access Database;DBQ=data\sampledata.mdb ];
ODBC CONNECT to [COSQL01;DATABASE=SALESDATA;Trusted_Connection = Yes];
OLEDB CONNECT32 TO [Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=Datasources\QWT.mdb]

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

15

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- Introduction to Qlikview data model
TEA BREAK /
Star Schema vs Snowflake Schema
EMAILS------------------------------------------------------------
Synthetic Key
ALL ABOUT
Circular reference
QVDS--------------------------------------------------------------- Best Practices & QA
THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
16
PM

03:00
PM
03:30
PM

BUILDING YOUR DATA MODEL


> 1) Introduction to Qlikview data model
The heart of a QlikView application is its data model.
It is composed of the different source tables that contain the information
and data used to measure a company's performance.
The data model is constructed by using QlikView's scripting language.
A correctly-built data model will associate all of its tables in a way which allows
us to manipulate the data however we like.
This means that the creation of analysis objects (charts) across different
dimensions depends mainly on how the data model is built and how its tables
are associated (how they are linked to each other).

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

17

Introduction to Qlikview data model.qvw

BUILDING YOUR DATA MODEL


> 2) Star Schema vs Snowflake Schema

star schema gets its name from the


al model's resemblance to a star
a fact table at its center and the dimension tables
ounding it representing the star's points

snowflake schema is similar to the star schema.


ever, in the snowflake schema,
ensions are normalized into multiple related tables

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

18

STAR Schema Vs SnowFlake Schema.qvw

BUILDING YOUR DATA MODEL


> 2) Star Schema vs Snowflake Schema
Snowflake Schema

Star Schema

Ease of maintenance /
change:

No redundancy and hence more


easy to maintain and change

Has redundant data and hence less


easy to maintain/change

Ease of Use:

More complex queries and hence


less easy to understand

Less complex queries and easy to


understand

Query Performance:

More foreign keys-and hence


more query execution time

Less no. of foreign keys and hence


lesser query execution time

Type of Datawarehouse:

Good to use for datawarehouse


core to simplify complex
relationships (many:many)

Good for datamarts with simple


relationships (1:1 or 1:many)

Joins:

Higher number of Joins

Fewer Joins

Dimension table:

It may have more than one


dimension table for each
dimension

Contains only single dimension table


for each dimension

When to use:

When dimension table is relatively When dimension table contains less


big in size, snowflaking is better as number of rows, we can go for Star
it reduces space.
schema.

Normalization/
De-normalization:

Dimension Tables are in


Normalized form but Fact Table is
still in De-Normalized form

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Both Dimension and Fact Tables are


in De-Normalized form
19

BUILDING YOUR DATA MODEL


> 3) Synthetic Key
When any two tables share more than one common field, QlikView creates a
complex key Called as Synthetic key, to try and associate both tables through
the combination of all of the common fields between them.
This takes the form of an additional table containing the shared fields and an
additional key field added to all involved tables. That table called as Sync Table
No
Synthet
ic Key

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Synthet
ic Key

20 Synthetic

Key.qvw

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Why avoid synthetic keys?

A simple synthetic key is usually not a problem


Longer reloadtime
Complex synthetic keys may lead to inconsistency of data
Performance issue

Different ways to undo synthetic keys :

Removing a field from one table


Concatenating the fields
Joining tables
Creating a Link/Key table

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

21

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Removing a field from one table
FactSales ::
LOAD
TransId,
MonthYear,
SalesAmount
FROM FactSales;;
As this is Budget fact
FactBudget:
table and MonthYear
LOAD
would be primary key
TransId,
here. THEN.
MonthYear,
BudgetAmount
FROM FactBudget;;
Drop this field from
FactBudget table.
Drop Field TransId FROM FactBudget;
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

22

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Concatenating the fields
FactSales ::
LOAD
TransId,
Month & Year AS MonthYear,
Month,
SalesAmount
Year,
FROM FactSales;;
SalesAmount
FROM FactSales;;

There are various


ways to rename table
fields.
We will learn about
this in details in our
session
SHAPE UP YOUR
DATA MODEL

FactBudget:
LOAD
Month,
Month & Year AS MonthYear,
Year,
BudgetAmount
BudgetAmount
FROM FactBudget;;
FROM FactBudget;;

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

23

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Joining tables
FactSales ::
LOAD
TransId,
Month,
Year,
SalesAmount
FROM FactSales;;

FactSales ::
LOAD
TransId,
Month,
Year,
SalesAmount
FROM FactSales;
Concatenate

FactBudget:
LOAD
TransId,
Month,
Year,
BudgetAmount
FROM FactBudget;;

So Final Table would be

FactBudget:
LOAD
TransId,
Month,
Year,
BudgetAmount
FROM FactBudget;;

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

24

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Creating a Link/Key table
FactSales ::
LOAD
TransId,
Month & _ &
Month,
Year AS LinkKey,
Year,
SalesAmount
FactSales;
FROM FactSales;;

We can resolve synthetic key by creating Link


key and Link table. We will learn this now how
to create .

FactBudget:
LOAD
TransId,
Month & _ &
Month,
Year AS LinkKey,
Year,
BudgetAmount
BudgetAmount
FROM FactBudget;;
FROM FactBudget;;

2) Remove Month & Year fields from FactSales


table

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

1) Create Link Key by concatenation Month


and Year from FactSales Table. Place some
separator between two field (viz ;
underscore _)

3) Create Link Key by concatenation Month


and Year from FactBudget Table. Place some
separator between two field (viz ;
underscore _)
4) Remove Month & Year fields 25from
FactBudget table

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Creating a Link/Key table
LinkTable::
LOAD
Month & _ &
Year AS LinkKey,
Month,
Year
FROM FactSales;
Concatenate
LOAD
Month & _ &
Year AS LinkKey,
Month,
Year
FROM FactBudget

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Now create new table called as


LinkTable
By concatenation below fields data from
FactSales and FactBudget
Month & _ & Year AS LinkKey,
Month,
Year
So our final
table would
be

26

BUILDING YOUR DATA MODEL


> 3) Synthetic Key (Contd..)
Creating a Link/Key table
So final data model without synthetic key
but additional key (LinkKey) and additional table (LinkTable)
would be

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Remove
27 Synthetic Key.qvw

BUILDING YOUR DATA MODEL


> 4) Circular reference
Similar to how synthetic keys are created,
a circular reference can also be the result of unwanted associations in our data
model
If there are circular references ("loops") in a data structure, the tables are associated
in such a way that there is more than one path of associations between two fields.
This type of data structure should normally be avoided as much as possible, since it
might lead to ambiguities in the interpretation of data.

In this example , To find a budget we have two


paths
1) FactSales.BudgetId >>
FactBudget.BudgetAmount

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

2) FactSales.BudgetId >> FactSales.Date


>> DimCalendar.MontYear >>
FactBudget.BudgetAmount
28

BUILDING YOUR DATA MODEL


> 4) Circular reference
This is an issue that needs to be addressed, and one that can
create severe data inconsistency problems
performance degradation
crashes.
To solve the presented scenario, and based on how we deal with synthetic keys in
the flow chart,
we should start by asking which of the created associations are correct and which
aren't.
In this case, the association between the FactBudget table and the Calendar table
is incorrect since the BudgetId is primary key in FactBudget table and
represent unique value for each month budget
Thats why in this case , We can remove field MonthYear from FactBudget table.
So our data model would look like

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Circulare
Reference.qvw
29

BUILDING YOUR DATA MODEL


> 5) Best Practices
Below are some best practices for qlikview scripting :
Add prefix Dim while giving name to dimenstion table (viz DimCustomer ,
DimProduct etc..)
Add prefix Fact while giving name to fact table (viz FactSales,FactBudget etc..)
Its good practice to split up your load script into several tabs. These split ups
must be logical ofcourse (viz create separate tab for each table load script)
It is better to keep the date fields outside the fact tables and create them in a
table of their own.
create MasterCalendar in your script and the link this table with your fact or
dimension table or with both using date field. Remove month / year column from
your fact / dimension table because those will be now in MasterCalendar
Putting comments in your scripts is good practice. It makes your scripts better
readable and understandable for other users.
In many situations you have different sets of databases to connect to. In the real
world youll probably have a development database, Quality Assurance databases
and
aAccenture
production
environment database.
Copyright
2013
All Rights Reserved.
30
Copyright
2013
Accenture Allwhen
Rights Reserved.
I can
imagine
your Qlikview application is under construction
or while
Best Practices.qvw

BUILDING YOUR DATA MODEL


> 5) Question & Answer
Q : Can we load XML file data in to Qlikview ? If yes then HOW ?
A : Yes , We can load XML file data into Qlikview. We can use File wizard which
is an option available in script editor.
Q : What is the shortcut to open Script Editor ?
A : CTRL + E
Q : What is the use of Relative Path option in Script Editor ?
A : This option is used if the data location is relative to or along the same path as
the current working directory.
Q : What are the various ways to remove synthetic key ?
A : Removing a field from one table
Concatenating the fields
Joining tables
Creating a Link/Key table
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

31

TEA BREAK !!!!!!

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

32

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- What is QVD ?
ALL ABOUT
How to create & use QVD ?
QVDS---------------------------------------------------------------
and un-optimized QVD
THE LOAD Optimized
load
STATEMENT--------------------------------------------------------- Best Practices & QA
CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
33
PM

03:00
PM
03:30
PM

ALL ABOUT QVDs


> 1) What is QVD ?
A QVD file is a file containing a table of data exported from Qlikview.QVD is a
native QlikView format. It can only be written to and read from QlikView. The file
format is optimized for speed when reading from a QlikView script but it is also
very compact. Reading data from a QVD file is typically 10-100 times faster than
reading from other source files.
QVD File Format:- A QVD file is an attempt to strike a compromise between
excellent QlikView performance both reading and writing the files and compact
representation. A QVD file contains exactly one table. Conceptually it is quite
similar to any typed file.
A QVD file consists of 3 parts
-- A well formed XML header
-- Symbol tables in a byte stuffed format.
-- Actual table data in a bit-stuffed format.
Uses of QVD file
--Increasing Load Speed
--Decreasing Load on Database Servers
-- Consolidating Data from Multiple QlikView Documents
-- Incremental
Copyright
2013 Accenture All Load
Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

34

ALL ABOUT QVDs


> 2) How to create QVD ?
Explicitly created and named from the script by means of the STORE command.
Simply state in the script that you want a previously read table or part of a
resident table to be exported to an explicitly named filename at a location chosen
by you.
FactSales ::
LOAD
TransId,
SalesMonthYear,
SalesAmount
FROM FactSales;;
STORE FactSales INTO FactSales.QVD;
FactSales ::
LOAD
TransId,
SalesMonthYear,
SalesAmount
FROM FactSales;;
STORE FactSales INTO D:\Training\QVD\FactSales.QVD;
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

35

ALL ABOUT QVDs


> 2) How to use QVD ?
You can simply use LOAD statement to load data from QVD in Qlikview
document.
You can either write LOAD statement manually OR you can use Table Files
option to file wizard.
FactSales ::
LOAD
TransId,
SalesMonthYear,
SalesAmount
FROM FactSales.QVD (qvd);;

FactSales ::
LOAD
TransId,
SalesMonthYear,
SalesAmount
FROM [D:\Training\QVD\FactSales.QVD] (qvd);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

36

ALL ABOUT QVDs


> 3) Optimized and un-optimized QVD load
If there is no transformation (calculation) on the fields and no filter in used
WHERE clause then that LOAD called as Optimized LOAD
FactSales ::
LOAD
TransId,
SalesMonthYear,
SalesAmount
FROM FactSales.QVD (qvd);;
If there is transformation (calculation) on the fields or filter used in WHERE clause
then that LOAD called as Non-Optimized LOAD
FactSales ::
LOAD
TransId,
UPPER(SalesMonthYear),
SalesAmount
FROM [FactSales.QVD] (qvd)
WHERE SalesAmount > 0;
Optimized load is much faster and therefore preferable, especially for larger data
sets.

Copyright 2013 Accenture All Rights Reserved.

Copyright 2013 Accenture All Rights Reserved.

37

How to create and use QVD.qvw

ALL ABOUT QVDs


> 4) Best Practices
Below are some best practices for use of QVD in Qlikview application:
Use another QLIKVIEW application other than your final QLIKVIEW dashboard for
QVD generation. Do all transformation and filters whenever possible in the source
query itself and create QVD for final result. Use variable to provide name for table
and QVD file name and write each QVD generation script in separate tab
whenever
SET vTable=Sales;
Sales
:: possible.
LOAD
TransId,
SalesMonthYear,
SalesAmount;
SQL SLECT * FROM Sales;
STORE Sales INTO Sales.qvd;

$(vTable)::
LOAD
TransId,
SalesMonthYear,
SalesAmount;
SQL SLECT * FROM Sales;
STORE $(vTable) INTO $(vTable).qvd;

LOAD always from QVD files.


LOAD only those fields you really need (pretty obvious, but "LOAD *" or "SELECT *"
are usual).
Avoid RESIDENT loads. If needed, load twice from a QVD.

Copyright 2013 Accenture All Rights Reserved.

Copyright 2013 Accenture All Rights Reserved.

38

ALL ABOUT QVDs


> 5) Question & Answer
Q : Can we read QVD from tool other than Qlikview?
A : No , QVD can only be written to and read from QlikView.
Q : What is the syntax to create QVD ?
A : STORE TableName INTO QVDFolderPath\TableName.QVD;
Q : How many tables data we can store into one QVD?
A : Qlikview can store and read only one table data into and from one QVD.
Q : Tell me some best practices to use and create QVD ?
A : Always create QVD into another qlikview application other than your actual
Qlikview Dashboard and name it as Project_QVD_Generator.
LOAD only those fields you really need.
Avoid RESIDENT loads. If needed, load twice from a QVD.
Use variable whenever possible in QVD generator for the central control over
table / file names.
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

39

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
Introduction to LOAD Statement
QVDS---------------------------------------------------------------- Syntax of LOAD statement
THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
40
PM

03:00
PM
03:30
PM

THE LOAD STATEMENT


> 1) Introduction
LOAD Statement is used to load data from file/database/inline/resident table.
The Load statement is composed of:
The names of the fields we want to load from the source table.
The From statement, specifying the location of the file we want to read. The
location can be specified either as a full path or a relative path.
The attributes we set about the file for QlikView to load it appropriately. In this
case, this part contains only the string (qvd). In other cases it may include
other important properties.
Most of the time , you can generate this LOAD Statement to load data from
file or from database using wizard.
There are basically two wizards available in script editor to guide you to create
correct LOAD statement for data load.

File Wizard : You can open this wizard by clicking Table Files.. button
from script editor.

Table All
Wizard
: You can open this wizard by clicking Select..
button from
Copyright 2013 Accenture
Rights Reserved.
41
Copyright
Accenture All Rights Reserved.
script 2013
editor.

THE LOAD STATEMENT


> 2) Syntax of LOAD statement
Load [distinct] * fieldlist
[( from file [ format-spec] | from_field field [format-spec] |
inline [format-spec ] data |
resident table-label |
autogenerate size)]
[ where criterion | while criterion]
[ group by fieldlist]
[ order by field [sortorder] {, field [sortorder] } ]
Where distinct is a predicate used if only the first of duplicate records
should be loaded.
FactBudget:
LOAD MonthYear,
Example of LAOD Statement.
Product,Amount
FactSales ::
DimStatus ::
LOAD
LOAD * INLINE FROM
FY_Budget.xlsx
TransId,
[Id,Status
(ooxml, embedded
SalesMonthYear,
0,Not Done
labels,
SalesAmount
1,Done ];
table is
SQL SELECT * FROM FactSales;;
BudgetFY_1314);
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

The LOAD Statement.qvw

42

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS----------------------------------------------------------------
Introduction
THE LOAD
Forced Concatenation
NoConcatenation
STATEMENT--------------------------------------------------------- Scenario (Best use of Concatenation)
CONCATENATION &
Introduction to JOINs
JOINS----------------------------------------------------- KEEP Statement
LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
43
PM

03:00
PM
03:30
PM

CONCATENATION & JOINS


> 1) Introduction to CONCATENATION
The CONCATENATE statement is a prefix to the LOAD statement.
This statement appends the rows of one table to another table.
Let us again consider the below two tables :
This concatenate keyword is
optional .
Employee:
When field names are same
Employee
LOAD
between two tables and both
I
Na
Positi
Id,
load scripts Employee
are one after
d me
on
Name,
another thenI Qlikview
Na
Positi
Position
1 Joy
ASE
automatically
d concatenate
me
on the
FROM Employee.qvd(QVD);
tables and make it one table
2 John SE
1 Joy
ASE
and choose table name as first
Concatenate (Employee)
New Employee
table name. 2 John SE
I Nam Positi
3 Brad SSE
LOAD
d e
on
Id,
4 Isaa AM
3 Brad SSE
Name,
c
Position
4 Isaac AM
FROM
[New Employee].qvd(QVD);

Concatenation.qvw

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

44

CONCATENATION & JOINS


> 2) Forced Concatenation
Forced concatenation happens when we explicitly define that two tables should be
combined into one logical table in the data model, even if they don't have the same
structure or field names.
Sales_Budget:
LOAD
Month,
Sales
Region,
Mont Regio Actual
[Actual Amount]
Sales_Budget
h
n
Amou
FROM
Mont Regi Actual
nt
Sales.qvd(QVD);
h
on
Amou
Jan12 APAC
1000
nt
Concatenate
Feb1 EMEA 2000
(Sales_Budget)
2Budget
Jan12 APAC 1000
LOAD
Mont Regi Budge
Month,
h
on
t
Feb12 EMEA 2000
Region,
Amou
Jan12 APAC [Budget Amount]
nt
FROM
Feb12 EMEA Jan12 APAC 1500
Budget.qvd(QVD);
Feb12 EMEA 2500
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

Budg
et
Amou
nt
1500
2500

Forced45concatenation.qvw

CONCATENATION & JOINS


> 3) NoConcatenation
If both tables have the same structure (field names), they will automatically be
merged into one logical table in the QlikView data model.
In case we want to avoid the default behavior whenever this circumstance is
present in the script, we can add the NoConcatenate keyword as a prefix to the
Load statement of the second table so that QlikView continues treating them as
separate tables in the dataEmployee:
model.
Employee
Employee
LOAD
I
Na
Positi
I
Na
Positi
Id,
d me
on
d me
on
Name,
1 Joy
ASE
1 Joy
ASE
Position
FROM Employee.qvd(QVD);
2 John SE
2 John SE
New Employee
I Nam Positi
d e
on
3

Brad

Isaac AM

SSE

Copyright 2013 Accenture All Rights Reserved.

NoConcatenate
[New Employee]
LOAD
Id,
Name,
Position
FROM
[New Employee].qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.

New Employee
I
Nam Positi
d e
on
3

Brad

SSE

Isaac AM

46NoConcatenation.qvw

CONCATENATION & JOINS


> 4) Scenario (Best use of Concatenation)
Suppose for Sales Dashboard , You need sales actual data as well as Budget
data. So in this case instead of maintaining data into two separate tables merge
both tables data into one table as Sales_Budget.
Sales_Budget:
LOAD
Month,
Sales
Region,
Mont Regio Actual
[Actual Amount]
Sales_Budget
h
n
Amou
FROM
Mont Regi Actual Budg
nt
Sales.qvd(QVD);
h
on
Amou
et
Jan12 APAC
1000
nt
Amou
Concatenate
Feb1 EMEA 2000
nt
(Sales_Budget)
2Budget
Jan12 APAC 1000
LOAD
Mont Regi Budge
Month,
h
on
t
Feb12 EMEA 2000
Region,
Amou
Jan12 APAC 1500
[Budget Amount]
nt
FROM
Feb12 EMEA 2500
Jan12 APAC 1500
Budget.qvd(QVD);
Feb12 EMEA 2500
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

47

CONCATENATION & JOINS


> 5) Introduction to JOINs
The JOIN statement is a prefix to the LOAD statement.
It is used to join the table that is being loaded to a previously loaded table.
The two tables are joined using a natural join, this means that the columns in
both tables are compared and the join is made over those columns that have the
same column names.
This means that if multiple columns are shared between tables, the match will be
made over the distinct combinations of those columns.
By default, QlikView performs an outer join.
This means that the rows for both tables are included in the resulting table.
When rows do not have a corresponding row in the other table, the missing
columns are assigned null values.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

48

CONCATENATION & JOINS


> 5) Introduction to JOINs (Contd..)
INNER JOIN:
Only rows that can be matched between both tables will be kept in the result.
OUTER JOIN:
All rows will be kept in the result, rows that do not have a corresponding value in the other
table will get null values for the fields that are unique to that table. When no prefix is
specified, this is the default join type that will be used.
LEFT JOIN:
All rows from the first table and those rows from the second table that have a
corresponding key in the first table, will be included in the result. When no match is found,
null values will be shown for the columns that are unique to the second table.
RIGHT JOIN:
All rows from the second table and those rows from the first table which have a
corresponding key in the second table, will be included in the result. When no match is
found, null values will be shown for the columns that are unique to the first table.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

49

CONCATENATION & JOINS


> 5) Introduction to JOINs (Contd..)

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

50

CONCATENATION & JOINS


> 5) Introduction to JOINs (Contd..)
Below are the syntax of INNER , LEFT , RIGHT & OUTER Join
Table 1:
LOAD
A,
B,
C
FROM
Table1.qvd(QVD);

Table 1:
LOAD
A,
B,
C
FROM
Table1.qvd(QVD);

Table 1:
LOAD
A,
B,
C
FROM
Table1.qvd(QVD);

JOIN

INNER JOIN

LEFT JOIN

LOAD
A,
B,
C
FROM
Table2.qvd(QVD);

LOAD
A,
B,
C
FROM
Table2.qvd(QVD);

LOAD
A,
B,
C
FROM
Table2.qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

51

CONCATENATION & JOINS


> 5) Introduction to JOINs (Contd..)

Table 1:
LOAD
A,
B,
C
FROM
Table1.qvd(QVD);

Table 1:
LOAD
A,
B,
C
FROM
Table1.qvd(QVD);

RIGHT JOIN

OUTER JOIN

LOAD
A,
B,
C
FROM
Table2.qvd(QVD);

LOAD
A,
B,
C
FROM
Table2.qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

52

CONCATENATION & JOINS


> 6) KEEP Statement
The KEEP statement works in the same way that the JOIN statement does, with a
small difference. Instead of joining the result in a single table, the KEEP
statement keeps both original tables and filters (keeps) rows in one table based
on matching rows in another table. The same logic for INNER, OUTER, LEFT, and
RIGHT KEEP applies here as did with the JOIN statement.
Below is the syntax for KEEP statement
Table1:
LOAD
A,B,C
FROM
Table1.qvd(QVD);
Table2:
LEFT KEEP (Table1)
LOAD
A, B, C
FROM
Table2.qvd(QVD);
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

}
53

Joins & Keep.qvw

LUNCH BREAK !!!!!!

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

54

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- ApplyMap()
CONCATENATION
&
MapUsing
JOINS----------------------------------------------------- IntervalMatch()
CROSSTABLE()
LUNCH BREAK
/
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
55
PM

03:00
PM
03:30
PM

FUNCTIONS IN QLIKVIEW
> 1) ApplyMap()
ApplyMap is a lookup or mapping function in Qlikview. This function would lookup
KeyValue into lookup / Mapping table and replace it with the key in the existing
table.
So before exploring Applymap() function we have to first understand Mapping
Tables
By prefixing the LOAD statement with the MAPPING statement, we tell QlikView
that we want to create a mapping table. This is a specific type of table that has
the
following properties:
It can only have two columns, the first being the lookup value and the second
being the mapping value to return.
Map_Status:
Mapping
It is a temporary table. At the end of
the script, QlikView automatically
LOAD
removes the table from the data model.
StatusId,
Status
FROM
Status.qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.

Copyright 2013 Accenture All Rights Reserved.

56

FUNCTIONS IN QLIKVIEW
> 1) ApplyMap() (Contd..)
We then used the ApplyMap() function to look up the key value while loading the
table.
The ApplyMap() function uses three parameters:
The name of the mapping table to use
The search value, a field value or expression from the source table, that is
looked up in the mapping table.
An optional value that specifies what value to use when no match is found in
the mapping table; here we used the value Unknown. When no value is
specified, the search value is returned.
Event:
LOAD
EventId,
APPLYMAP(Map_Status,EventStatusId,No Status) As EventStatus
FROM Status.qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

57

ApplyMap.qvw

FUNCTIONS IN QLIKVIEW
> 2) MapUsing
Map..using is statement similar to APPLYMAP() function which would replace key
with its respective key value from lookup / mapping tables.
It is useful when we have multiple key fields with the same name so instead of
writing APPLYMAP() function each and every time you can define this statement
for that Key field at the beginning of table load but after declaration on mapping
table.
In our previous example , suppose there are two more tables which StatusId
key field and need to replace with respective status from Map_Status then you
can write below statement
MAP Status USING Map_Status;
Event:
LOAD
EventId,
EventStatusId AS Status
FROM Status.qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

58

Map Using.qvw

FUNCTIONS IN QLIKVIEW
> Best practices
Always create separate tab Mapping tables and write all mapping table script
there
Always add prefix Map_ while providing name to the mapping table.
Use Map..using instead of APPLYMAP() whenever possible
Provide Default value in APPLYMAP() function
UPPER case your key in mapping table as well as in table.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

59

FUNCTIONS IN QLIKVIEW
> Question & Answer
Suppose source tables are like :
Countr
yId

Country

Sales
Id

Countr
yId

Amou
nt

US

United
States

S1

US

100

S2

UK

200

UK

United
S3
JP
300
Kindom
Then
, What would be the output of below script ?
IN tell me
India
Map_Country:
Mapping
LOAD
UPPER(CountryId) AS CountryId,
Country
FROM Country.qvd(QVD);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

MAP Country USING Map_Country;


Event:
LOAD
SalesId,
UPPER(CountryId) AS Country,
Amount
FROM Sales.qvd(QVD);

60

FUNCTIONS IN QLIKVIEW
> Question & Answer
Suppose source tables are as below
Countr
yId

Country

Sales
Id

Countr
yId

Amou
nt

US

United
States

S1

US

100

S2

UK

200

United
Kindom

S3

JP

300

UK

Then
, What
would be the output of below script ?
IN tell me
India
Output
would
be
Map_Country:
MAP Country
Sales CountryId
Amou USING Map_Country;
Mapping
Event:nt
Id
LOAD
LOAD
S1
United
100
UPPER(CountryId) AS CountryId,
SalesId,
States
Country
UPPER(CountryId) AS Country,
S2
United Amount200
FROM Country.qvd(QVD);
Kindom FROM Sales.qvd(QVD);
S3
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

JP

300
61

FUNCTIONS IN QLIKVIEW
> IntervalMatch()
A common problem in business intelligence is when you want to link a number to
a range. It could be that you have a date in one table and an interval a From
date and a To date in another table, and you want to link the two tables. In
SQL, you would probably join them using a BETWEEN clause in the comparison.

But how do you solve this in QlikView, where you should avoid joins?

The answer is to use IntervalMatch.

IntervalMatch is a prefix that can be put in front of either a Load or a SELECT


statement. The Load/SELECT statement needs to contain two fields only: the
From and the To fields defining the intervals. The IntervalMatch will generate
all the combinations between the loaded intervals and a previously loaded
numeric field.

Typically, you would first load the table with the individual numbers (The Events),
then the table with the Intervals, and finally an intervalmatch that creates a third
table that bridges the two first tables.

IntervalMatch (Date)
IntervalMatch.qvw
Load
distinct
ToDate resident Intervals;
Copyright
2013
AccentureFromDate,
All Rights Reserved.
62
Copyright 2013 Accenture All Rights Reserved.

FUNCTIONS IN QLIKVIEW
> CROSSTABLE()
QlikView is also able to convert crosstables (a table where there is a column for
each dimension in a range) to traditional tables. For the file we are loading in this
example, we won't need this function, but it's important that you know about it
since this table structure is very common, particularly in budget spreadsheets.
An example of a crosstable is shown here

So after using CROSSTABLE , you output table would be


CrossTable(Month, Amount)
LOAD Department As Dept,
Jan, Feb, Mar, Apr, May, Jun
FROM DepartmentData.qvd (qvd);
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

Departm
ent

Mont
h

Amou
nt

Jan

160

Feb

336
63

CrossTable.qvw

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- Functions for manipulating string
Functions
LUNCH BREAK
/
for mathematical
calculation
EMAILS------------------------------------------------------- Question & Answer
FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
64
PM

03:00
PM
03:30
PM

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS
Like other programming language , Qlikview also has bunch of functions for
manipulating string.
String concatenation :
The most common operation performed on strings is concatenating two
or more strings together into a single string. This is achieved by using the &
operator.
For example:
[First Name] &' '& [Last Name]
This concatenates the values of First Name and Last Name, with a space
between them, into a single string containing the full name.
len(string) :
Returns the length of a string including blank spaces.
For Example :
The Result of len('QlikView) is 8.
The Result of len('QlikView Application) is 20.
left(string,number of characters) :
Starting from the left of the string, returns the specified amount of
characters.
Copyright
2013 Accenture All Rights Reserved.
65
2013 Accenture
All Rights Reserved.
ForCopyright
Example
:

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS (Contd..)
right(string,number of characters) :
Starting from the right of the string, returns the specified amount of
characters.
For Example :
The Result of right('QlikView,4) is View.
mid(string,starting character, number of characters (optional)) :
Returns a substring from the string, starting at the specified character.
Optionally, the
length of the substring can be specified. If no length is specified, the right-most
part of the
string (starting at the specified position) is returned.
For Example :
The Result of mid('QlikView,5,2) is Vi.
The Result of right('QlikView,5) is View.
index(string, substring, occurrence (optional)) :
Returns the position at which the substring is found in the string. If an
occurrence is specified, QlikView will look for that specific occurrence, otherwise
the first occurrence is assumed. If a negative number is supplied for occurrence,
QlikView
starts
searching
Copyright
2013 Accenture
All Rights
Reserved. from the end of the string.
66
Copyright
2013 Accenture
All Rightsthe
Reserved.
If no
match
is found,
function returns 0

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS (Contd..)
upper(string) :
Converts the string to upper case .
For Example :
The Result of upper('QlikView) is QLIKVIEW.
upper(string) :
Converts the string to lower case .
For Example :
The Result of upper('QlikView) is qlikview.
capitalize (string):
Capitalizes each word in the string.
For Example :
The Result of capitalize ('QlikView document') is Qlikview Document.
replace(string,search string, replace string) :
Replaces the search string in the string with the replace string.
For Example :
The Result of replace('QlikView','Qlik', 'Click') is ClickView.
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

67

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS (Contd..)
keepchar(string,characters to keep) :
Returns the string without the characters that are not specified in the
keep list.
For Example :
The Result of keepchar('QlikView,ike) is ikie.
purgechar (string, characters to purge) :
Returns the string minus the characters specified in the purge list.
For Example :
The Result of purgechar('QlikView,ie) is QlkVw.
textbetween (string, start text, end text, occurrence (optional)) :
Returns the substring found between the start and end text. If an
occurrence is specified QlikView will look for that specific occurrence, otherwise
the first occurrence will be assumed.
For Example :
The Result of textbetween ('<Qlik><View>,'<', '>') is Qlik.
The Result of textbetween ('<Qlik><View>,'<', '>,2) is View.

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

68

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS (Contd..)
trim(string) :
Returns the string without any leading and trailing spaces.
For Example :
The Result of trim( QlikView ,) is QlikView.
ltrim(string) :
Same as the trim function, but only removes leading spaces.
For Example :
The Result of ltrim( QlikView ) is Qlikview .
rtrim(string) :
Same as the trim function, but only removes trailing spaces.
For Example :
The Result of rtrim( QlikView ) is Qlikview.
all of these functions can be nested For Example
Amsterdam, Netherlands: Schiphol is our string from field [Destination Airport]
If we are only interested in extracting the actual name of the airport, the part
behind the colon,
we could use the following expression:
mid([Destination Airport], index([Destination Airport], ':') + 2)

Copyright 2013 Accenture All Rights Reserved.

Copyright 2013 Accenture All Rights Reserved.

69

String Manipulation.qvw

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS : Numbers and
numeric functions
Operat
or

Explanatio
n

Example

Result

Add

2+2

Subtract

10 5

Multiply

5*5

25

Divide

25 / 5

Function

Explanation

Example

Result

Ceil()

Round up. Optionally, a parameter


can
be specified to indicate which
multiple
to round up to.

Ceil(2.5)
Ceil(2.6, 0.25)

3
2.75

Floor()

Round down. Optionally, a


parameter
can be specified to indicate which
multiple to round up to.

Floor(2.5)
Floor(2.6, 0.25)

2
2.25

Round(3.14)
Round(3.16,700.1)
Round(3.14, 0.1)

3
3.20
3.10

Round the number. Optionally, a


parameter
can be specified to
Copyright 2013 Accenture All Rights
Reserved.
Copyright 2013 Accentureindicate
All Rights Reserved.

Round()

STRING MANIPULATION AND


MATHEMATICAL FUNCATIONS : Date & Time
functions
Function

Explanation

Example

Result

Year()

Returns the year part of the date.

Year(Date)

2012

Month()

Returns the month part of


the date.

Month(Date)

Week()

Returns the ISO week number of the


date.

Week(Date)

21

Day()

Returns the day of the month.

Day(Date)

22

Weekday( Returns a number between 0


)
(Monday) and 6 (Sunday),
representing the day of the week.

Weekday(Date)

Hour()

Returns the hour part of the time.

Hour(Date)

10

Minute()

Returns the minute part of the time.

Minute(Date)

15

Today()

Returns today's date, without a


timestamp.

Today()

2013-1115

MakeDat
e()

Creates a date from the supplied


MakeDate(2013,
2013-11year, month, and day. If no day is
11, 15)
15
specified, the first day of the month
MakeDate(2013,
2013-11is assumed. If no month is specified,
11)
01
Copyright 2013 Accenture
All
Rights
Reserved.
71
the first month of the year is
MakeDate(2013)
2013-01Copyright 2013 Accenture All Rights Reserved.
Mathematical Functions and Date Time Functions.qvw
assumed.
01

TEA BREAK !!!!!!

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

72

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- PICK()
INABOVE()
FUNCTIONS
EXISTS()
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
73
PM

03:00
PM
03:30
PM

ADVANCE FUNCTIONS IN QLIKVIEW


> PICK()
Another interesting and powerful conditional function available in QlikView is the
Pick function.
In a way, it can be said to act as a simplified nested If. The parameters this
function takes are:
Pick(n, expr1, expr2)
Where
n is an integer number that determines which of the subsequent expressions
should be evaluated. expr1 is an expression to be evaluated when n= 1
expr2 is an expression to be evaluated when n= 2
The same result of the Pick function can be accomplished using a nested If;
for example:
If (n = 1, expr1, If(n = 2, expr2))
However, we can easily see that the Pick function is much simpler to use in this
Pick.qvw
case
Copyright
2013 Accenture All Rights Reserved.
74
Copyright
2013 Accenture
Rights Reserved.
and
can even
be Alllighter
in terms of resource usage.

ADVANCE FUNCTIONS IN QLIKVIEW


> ABOVE() & BELOW()
above( [ total ] expression [, offset [,n ]] )
Returns the value of expression evaluated with the chart's dimension values as
they appear on the row above the current row within a column segment in a
table or, in the case of image charts, in the chart's straight table equivalent.
On the first row of a column segment a null value will be returned,
as there is no row above.
below( [ total ] expression [, offset [,n ]] )
Returns the value of expression evaluated with the chart's dimension values as
they appear on the row below the current row within a column segment in a
table or, in the case of image charts, in the chart's straight table equivalent.
On the last row of a column segment a null value will be returned,
as there is no row below.

Above.qvw
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

75

ADVANCE FUNCTIONS IN QLIKVIEW


> EXISTS()
exists( field [ , expr ] )
Determines whether a specific field value exists in a specified field of the data
loaded so far. Field is a name or a string expression evaluating to a field name.
The field must exist in the data loaded so far
by the script. Expr is an expression evaluating to the field value to look for in the
specified field. If omitted, the current records value in the specified field will be
assumed.
Examples:
exists( Month, 'Jan' )
returns -1 (true) if the field value Jan can be found in the current contents of
the field Month.
exists( IDnr, IDnr )
returns -1 (true) if the value of the field IDnr in the current record already
exists in any previously read record containing
that field.
exists( IDnr )
Copyright
2013 Accenture
All Rights
Reserved.
is identical
with
the
previous example.

Copyright 2013 Accenture All Rights Reserved.

76

Exists.qvw

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
IFTHENELSEEND IF
QLIKVIEW---------------------------------------------------- LOOPS
- SELECT CASE
STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
77
PM

03:00
PM
03:30
PM

CONTROL STATEMENTS AND LOOPS


> IFTHENELSEEND IF
IF THEN ELSEIF ELSE END IF
Follow a different path based on which condition is met, this is the control
statement
we used in our example.
The ELSEIF and ELSE conditions are optional.
IF i = 1 THEN
[executed when i = 1]
ELSEIF i = 2 THEN
[executed when i = 2]
ELSE
[executed when i not 1 or 2]
END IF
IF() :
This is also same as above but this is inline IF statement.
IF(i=1 , [executed when i = 1] , [executed when i not 1])
IFTHENELSE.qvw
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

78

CONTROL STATEMENTS AND LOOPS


> Loops
DO LOOP :
Execute statements WHILE or UNTIL a condition is met.
Syntax :
DO WHILE i< 10
[executed while i is less than 10]
LOOP
FOR NEXT :
Use a counter to loop over statements.
Syntax :
FOR i = 1 TO 10
[executed for values 1 to 10]
NEXT
FOR EACH NEXT :
Loop over statements for each value in a comma separated list.
Syntax :
FOR EACH i IN A, B, C
[executed for A, B and C]
NEXT
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

Looping.qvw

79

CONTROL STATEMENTS AND LOOPS


> SELECT CASE
SWITCH CASE DEFAULT END SWITCH :
Execute a different group of statements (CASE) based on the value of an
expression.
If no match is found for the value, the DEFAULT statements are executed.
Syntax :
SWITCH i
CASE 1
[executed when i is 1]
CASE 2
[executed when i is 2]
DEFAULT
[executed when i not 1 or 2]
END SWITCH

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

80 SWITCH

Case.qvw

Generic LOAD
Another table structure we can come across when loading data into QlikView is
what we call a generic table.
A generic table is commonly used to store attribute values for different objects.
These attributes are not necessarily shared across all objects contained in the
table, and that's one of the reasons why a traditional columnar structure is not
used for these tables.

Objec
t
Ball
Ball
Ball
Coin
Coin
Coin

Attribut
e
Value
Color
Yellow
Weight 120 g
Diameter 8 cm
Color
Gold
Value
$100
Diameter 2.5 cm

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

81Generic

Load.qvw

Agenda
BASIC OF QLIKVIEW
SCRIPTING---------------------------------------------- BUILDING YOUR DATA
MODEL----------------------------------------------- TEA BREAK /
EMAILS----------------------------------------------------------- ALL ABOUT
QVDS--------------------------------------------------------------- THE LOAD
STATEMENT-------------------------------------------------------- CONCATENATION &
JOINS----------------------------------------------------- LUNCH BREAK /
EMAILS------------------------------------------------------- FUNCTIONS IN
QLIKVIEW----------------------------------------------------- STRING MANIPULATION AND MATHEMATICAL
Copyright 2013 Accenture All Rights Reserved.
FUNCATIONS-------Copyright
2013 Accenture All Rights Reserved.

09:00
AM
09:15
AM

09:15
AM
10:00
AM

10:00
AM

10:30
AM

10:30
AM

11:00
AM

11:00
AM
11:10
AM

11:10
AM
12:30
PM

12:30
AM

01:30
PM

01:30
PM
03:00
82
PM

03:00
PM
03:30
PM

SHAPE UP YOUR DATA MODEL


QUALIFY / UNQUALIFY :
The Qualify keyword can be used to qualify field names with their corresponding
table name, which basically renames the specified fields in the form of
tablename.
fieldname, thus ensuring no unwanted associations are created.
Syntax : QUALIFY * ;
UNQUALIFY * ;
QUALIFY CustomerId;
QUALIFY *;
UNQUALIFY OrderId;

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

Qualify_UnQualify
.qvw
83

SHAPE UP YOUR DATA MODEL


RENAME FIELDS/ALIAS :
Renaming tables or fields in QlikView is done using the RENAME statement.
The following code shows some examples of this statement:
RENAME TABLE [Order Types] TO [OrderTypeMaster];
RENAME FIELD [%Order Type ID] TO [OrderGroupID];
Or
you can use AS keyword in load statement to rename the fields
The following code shows some examples of this statement:
LOAD
Date AS OrderDate
OrderId
Amount
FROM Order.QVD (qvd);

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

84 Rename

Fields.qvw

SHAPE UP YOUR DATA MODEL


DROP FIELDS / TABLES:
Removing unused fields from the data model is a quick win in most QlikView
applications. It can save anywhere between a few to hundreds of MB on bigger
documents. Text fields, in particular, can take up a lot of space.
As the developer, you will probably have an idea of fields that are definitely not
being used. You can either remove those from the script, or comment them out if
you want to play it safe.
Removing fields OR Tables in QlikView is done using the DROP statement.
The following code shows some examples of this statement:
DROP TABLE [Order Types];
DROP FIELD [%Order Type ID];

Drop Table_Drop Field.qvw


Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

85

Question ???

Any
Questi
ons?
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

86

References
1. WWW.Qlikview.com
2. Qlikview 11 Developer book (PDF)
3. Qlikview 11 Reference Manual (PDF)

Copyright 2013 Accenture All Rights Reserved.


Copyright 2013 Accenture All Rights Reserved.

87

Thank
You
Copyright 2013 Accenture All Rights Reserved.
Copyright 2013 Accenture All Rights Reserved.

88

Potrebbero piacerti anche