QlikView Essentials - Sample Chapter
QlikView Essentials - Sample Chapter
QlikView Essentials - Sample Chapter
ee
pl
e
P r o f e s s i o n a l
$ 34.99 US
22.99 UK
P U B L I S H I N G
Sa
E x p e r t i s e
D i s t i l l e d
QlikView Essentials
Chandraish Sinha
QlikView Essentials
QlikView Essentials
Chandraish Sinha
P U B L I S H I N G
Preface
The data is growing at a higher pace so does the need to understand data. There
are many applications that perform data analysis and design, but QlikView takes
Business Intelligence to the next level. The ability of QlikView to extract and present
the data in a way that the human mind thinks, has made QlikView hugely popular.
The associative nature of the QlikView data model has made business discovery
fairly simple.
This book is being designed in a way that provides equal value to a novice BI
developer and a seasoned practitioner. This book starts with the basics of QlikView,
data warehousing and works through creating data models and visualizations. This
book covers all the topics for the QlikView designer and developer and can be used
as a reference guide in new or ongoing implementations.
Each chapter in the book follows a structure:
Each chapter will cover the essentials of the topic in the chapter.
This book uses the Adventure Works database; most readers will have
familiarity with this database. There is tons of information available online
on this database, so users will easily understand.
This book also comes with data in MS Access, Excel, and text files. It is also
accompanied with QlikView solutions/qvw's that the reader can download
and follow.
Preface
Let's review the data model that we created in the last chapter:
[ 39 ]
One of our requirements is to create a robust data model that is clean, easy to
understand, and helps in data analysis. This chapter describes techniques to achieve
this requirement. By understanding and applying the concepts of mapping load,
concatenate, and joins, we can create a more useful data model.
Mapping tables must have two columns. Even if the table has more columns,
you can use only two columns at a time to achieve mapping table functionality.
The same table can be used multiple times in case other columns need to be
mapped.
The first column is always a key (ID) column. The second column contains
the desired mapping value. The first column field name can differ between
the mapping table and the mapped table.
Use the ApplyMap function in the table to compare the key/ID field to get
the desired mapping value.
Looking at the previous data model, you can identify the tables that are good
candidates for mapping load. These tables will be:
Territory
ProductSubcategory
Product Category
CountryRegion_Inline
[ 40 ]
Chapter 3
5. Navigate to the Dimensions tab and cut the load script of SalesTerritory
and paste it in the Mapping tab.
6. Navigate to the Mapping tab, change the comment, and name the table as
Territory_Map.
7. Prefix the load statement with the Mapping keyword. This will treat the
SalesTerritory table as a mapping table. This table will not be present in
the memory and will get dropped after the script execution.
8. Make the first column as the ID column and name it TerriID, and name the
second column as TerriDesc. Names are optional.
9. The mapping table load script should look like the following:
[ 41 ]
10. Navigate to the Orders tab, and go to the last line in the Orders table load
statement after TotalDue. Add "," after TotalDue. Use the ApplyMap function
to add a TerritoryDesc column in the Orders table. Name this column as
[Order Territory].
ApplyMap('Territory_Map',TerritoryID,'Territory Not Found') As
[Order Territory]
[ 42 ]
Chapter 3
You will see a new field is being created. Notice Territory Not Found
because in some cases no match is found between the two tables.
[ 43 ]
6. Save and execute your script. Review your data model in Table Viewer to see
that the Product Category table is removed and Category Desc is added to
the ProductSubcategory table.
[ 44 ]
Chapter 3
3. Navigate to the Dimensions tab and go to the last line of the Product
load script. Use ApplyMap to add SubCategoryName and CategoryName
to the Product table. ApplyMap statements in the Product table will appear
as follows:
4. Save and load the script. View your data model in Table Viewer.
The ProductSubcategory table is removed and SubCategoryName
and CategoryName is added to the Product table.
4. Navigate to the Dimensions tab. Go to the load script of the Customers table
and, in the last line, use ApplyMap as follows:
[ 45 ]
6. Review the data model in Table Viewer. The data model so far will appear as
follows. It is much cleaner with fewer tables.
Concatenation
Another way to optimize your data model in QlikView is through concatenation.
Concatenation is a way to combine or merge tables. It is similar to Union All in SQL.
It appends rows from one table to another. The result of concatenation between two
tables (Table1 and Table2, for example) is that a new table contains the sum of the
numbers of records in Table1 and Table2. Concatenate is used when you have two
fact tables in your data model. Two fact tables are not good for your data model. You
can combine them using concatenate or link tables. Link tables are explained in the
next chapter.
Concatenate is also useful when you have to combine two tables with similar
structures. Say, for example, your organization has an Employee table that stores
employee data. Your organization buys another company and now wants to merge
the details of the employees of this new company with the existing Employee table.
[ 46 ]
Chapter 3
Automatic concatenation: If the field names and the number of fields in two
or more tables are exactly the same, QlikView will automatically concatenate
the output of the different load statements into one table.
Forced concatenation: If the field names and the number of fields in two
or more tables are NOT exactly the same, QlikView will allow you to force
concatenation by the use of Concatenate keyword.
Concatenation example
Create an Inline table in QlikView to understand the concept of concatenation:
Automatic Concatenation
1. Navigate to the Inline tab.
2. Create two Inline tables as shown in the following:
[ 47 ]
NoConcatenate
Use the same script and add NoConcatenate between the two load scripts:
In Table View you will see two tables, Table1 and Table2. You will see that the
synthetic key between them, as column names in the tables, are the same.
Forced concatenation
To test force concatenation, comment the previous Table1 and Table2 load scripts.
1. Now create two tables with different columns and use the Concatenate
keyword to force concatenation.
2. After executing the script, notice that Table Viewer shows one single table,
Table1. Even though the column names in the two tables are different,
QlikView merged them.
[ 48 ]
Chapter 3
Joins
Joins in QlikView are similar to joins in SQL. Joins between two tables always result
in one table. With joins, the columns of the two tables are affected. Joins are explicitly
made by using inner join, left join, right join, and outer join.
In QlikView, joins work in the following ways:
Inner join: Only the matching records in the two tables are stored.
Left join: All the records from the first/left table are kept, and only those
records from the second table that match a record in the first table are kept.
Right join: All the records from the second/right table are kept, and only
those records from the first table that match a record in the second table are
kept.
Outer join or join: Records from both the tables will be stored and, where
possible, records will be matched.
Use Joins.qvw to practice different kinds of joins and
concatenate options. It is located in your Apps folder.
[ 49 ]
5. Observe the data model in Table Viewer and you will see the Orders and
Order Detail tables have combined into one table, Orders.
[ 50 ]
Chapter 3
Aggregating data
We have combined the Orders and Order Detail tables; now it is time to find the
sales amount for each of these orders by aggregating the data by OrderID:
1. Use QlikViewEssentials_Chap3.qvw. Navigate to the Orders tab in your
script editor.
2. Navigate to the empty space after the Order Detail load statement.
3. Perform "resident load" from the Orders table and aggregate using the Group
By function. Resident load is used here as the Orders table is already loaded
in the script and we can reuse the same table using resident load.
4. It will be better to keep [Order Sales Amt] in the Orders table as it is at the
Order level. To achieve this, go to the empty space above the load statement
and type left join(Orders).
5. Your script should appear as the following:
[ 51 ]
The new employee file structure is similar to the Employees table loaded in QlikView.
This new employee file NewEmployees.xlsx is also located in the same location:
1. Navigate to the Employees tab in QlikViewEssentials_Chap3.qvw.
2. Go to the empty space after the SalesPerson load script.
3. Click on Table Files and browse to NewEmployees.xlsx, which is located
under C:\QlikViewEssentials\Data. Make sure to select Embedded labels
under Labels while selecting the file.
4. Remove the directory. Save and reload your script. You will observe just
one table, Employees, in the data model and it will have records of both
Employees and NewEmployees.
5. The script of the NewEmployees table will appear as the following:
[ 52 ]
Chapter 3
Summary
QlikView always desires a star schema as it is simple to understand and efficient for
reporting. In this chapter, we learned different techniques of creating a star schema
and converted our previously created data model into a star schema by using
mapping loads, joins, and concatenation.
In the next chapter, we will learn about data modeling challenges, which are
resolved by using cross tables, link tables, and the master calendar. You will also
learn about handling slowly changing dimensions using the Interval Match
function. Finally we will use QVDs to read and write our data model tables.
[ 53 ]
www.PacktPub.com
Stay Connected: