QlikView Essentials - Sample Chapter

Embed Size (px)

Citation preview

  • 7/25/2019 QlikView Essentials - Sample Chapter

    1/21

    P r o f e s s i o n a l E x p e r t i s e D i s t i l l e

    Want to solve your Business Intelligence headaches?

    Learn how QlikView can help, and discover a powerful

    yet accessible BI solution that lets you harness your data

    QlikView Essentials

    Chandraish SinhaP U B L I S H I N GU L I S H I N

    professional expertise dis

  • 7/25/2019 QlikView Essentials - Sample Chapter

    2/21

    In this package, you will find: The author biography

    A preview chapter from the book, Chapter 3 'Optimizing Your Data Model'

    A synopsis of the books content More information on QlikView Essentials

  • 7/25/2019 QlikView Essentials - Sample Chapter

    3/21

    About the Author

    Chandraish Sinhais a Business Intelligence enthusiast from Ohio. He brings17 years of experience in providing cost-effective BI solutions.

    He is responsible for many QlikView implementations in various industries, namelyfinancial, insurance, pharmaceuticals, and event management. He currently holdsQlikView Designer and QlikView Developer certifications.

    He shares his knowledge and passion through his QlikView blog(http://www.learnallbi.com/).

    He currently works as an independent BI consultant and helps organizations inimplementing BI solutions.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    4/21

    PrefaceThe data is growing at a higher pace so does the need to understand data. Thereare many applications that perform data analysis and design, but QlikView takesBusiness Intelligence to the next level. The ability of QlikView to extract and presentthe 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 discoveryfairly simple.

    This book is being designed in a way that provides equal value to a novice BIdeveloper and a seasoned practitioner. This book starts with the basics of QlikView,data warehousing and works through creating data models and visualizations. Thisbook covers all the topics for the QlikView designer and developer and can be usedas 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 covers both QlikView developer/Data model and QlikViewdesigner/visualization topics.

    Each topic is explained first and then followed by a stepby-step exercise.Readers can follow these exercises to create their own data model anddash boarding application.

    This book uses the Adventure Works database; most readers will havefamiliarity with this database. There is tons of information available onlineon 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 downloadand follow.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    5/21

    Preface

    What this book coversChapter 1, QlikView Essentials, provides the basics of QlikView. It gives an overviewof the QlikView architecture. It also provides instructions on how to downloadQlikView. You get to know about the star schema and learn about the underliningdata model used in the book.

    Chapter 2, Extract, Transform, and Load, as the name suggests, dives into buildinga data model in QlikView by extracting, transforming, and loading data. In thischapter, readers will learn about using scripts to load data from different sourcesand data transformation.

    Chapter 3, Optimizing Your Data Model, deals with techniques to optimize a data model.This involves different ways to join data and data aggregation.

    Chapter 4, Data Modeling Challenges, helps you in understanding and resolvingdifferent data modeling challenges. You learn about loading some special tabletypes. You will also learn about the best practices of data modeling.

    Chapter 5, Creating Dashboards, gives you the opportunity to learn about differentdash boarding practices and create different visualization objects.

    Chapter 6, Comparative Analysis, enforces the importance of data comparison inthe dashboards using Set Analysis and Alternate State. You also learn aboutimplementing what-if analysis.

    Chapter 7, Securing Your Application, teaches how to secure your dashboard application.

    Chapter 8,Application Deployment, provides an overview of servers and howapplications can be deployed on the server.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    6/21

    [39 ]

    Optimizing Your Data ModelYour data model should always be simple and easy to understand. An expert datamodeler will always clean up the data model to remove any unnecessary tables.

    QlikView provides different techniques for data model cleanup. In this chapter wewill learn ways to clean up the data model and create a star schema.

    In this chapter we shall:

    Learn about mapping tables and mapping load

    Clean up the data model using "mapping load" and "apply map"

    Learn about different kinds of joins

    Aggregate data

    Learn to use "concatenate"

    Let's review the data model that we created in the last chapter:

  • 7/25/2019 QlikView Essentials - Sample Chapter

    7/21

    Optimizing Your Data Model

    [40 ]

    One of our requirements is to create a robust data model that is clean, easy tounderstand, and helps in data analysis. This chapter describes techniques to achievethis requirement. By understanding and applying the concepts of mapping load,concatenate, and joins, we can create a more useful data model.

    Mapping table essentialsMapping tables are very useful in QlikView data modeling. Some of the uses ofmapping tables include data cleansing, renaming the data source-specific columnnames with business-friendly names, and providing comments in the script. Thefollowing points discuss some of the components and properties of mapping tables:

    Mapping load is used to reduce the number of tables in a data model.Mapping prefix is used to create a mapping table. Mapping tables areused only for field mapping and are automatically dropped after scriptexecution.

    These are usually the look-up tables. 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 bemapped.

    The first column is always a key (ID) column. The second column containsthe desired mapping value. The first column field name can differ betweenthe mapping table and the mapped table.

    Use theApplyMapfunction in the table to compare the key/ID field to getthe desired mapping value.

    It provides a third optional parameter when no comparison is found.

    Looking at the previous data model, you can identify the tables that are goodcandidates for mapping load. These tables will be:

    Territory

    ProductSubcategory

    Product Category

    CountryRegion_Inline

  • 7/25/2019 QlikView Essentials - Sample Chapter

    8/21

    Chapter 3

    [41 ]

    Mapping load Territory tableThe objective here is to add TerritoryDescto the Orderstable and remove theTerritorytable from the data model. This will help in data model cleanup as onetable will be reduced:

    1. As a best practice, all mapping loads should be in one tab. This tab should bethe very first tab in the script after the Maintab.

    2. Open the QlikView file QlikViewEssentials.qvwthat you have been usingso far. Save as QlikViewEssentials_Chap3.qvw.

    3. Invoke the script editor by pressing Ctrl+ E.

    4. Create a new tab and name it Mapping. Move this tab all the way to the leftby using the Promote Tab icon as highlighted in the following screenshot. Itshould be your tab after the Maintab.

    5. Navigate to the Dimensionstab and cut the load script of SalesTerritoryand paste it in the Mappingtab.

    6. Navigate to the Mappingtab, change the comment, and name the table asTerritory_Map.

    7. Prefix the load statement with the Mappingkeyword. This will treat theSalesTerritorytable as a mapping table. This table will not be present inthe memory and will get dropped after the script execution.

    8. Make the first column as the ID column and name it TerriID, and name thesecond column as TerriDesc. Names are optional.

    9. The mapping table load script should look like the following:

  • 7/25/2019 QlikView Essentials - Sample Chapter

    9/21

    Optimizing Your Data Model

    [42 ]

    10. Navigate to the Orderstab, and go to the last line in the Orderstable loadstatement after TotalDue. Add "," after TotalDue. Use theApplyMapfunctionto add a TerritoryDesccolumn in the Orderstable. Name this column as[Order Territory].

    ApplyMap('Territory_Map',TerritoryID,'Territory Not Found') As

    [Order Territory]

    This is theApplyMapsyntax. Here, Territory_Mapis the name of themapping table. TerritoryIDis the lookup column. 'Territory NotFound'is an optional parameter in case the match is not found.

    11. Your Orderstable script should look like the following:

    12. Reload your script.

    13. Navigate to Table Viewer (Ctrl+ T) .You will notice that the Territorytable has gone and the Order Territorycolumn has been added to theOrderstable.

    14. Create a list box for Order Territory.

    15. To create a list box, close the script editor by clicking OK. Anywhere in

    the empty space on the sheet, right click and choose New Sheet Objectand select List Box. In the properties of the list box, select Order Territoryunder the Fieldsection.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    10/21

    Chapter 3

    [43 ]

    You will see a new field is being created. Notice Territory Not Foundbecause in some cases no match is found between the two tables.

    Mapping load Product Category andProductSubcategory tablesHere the objective is to add the [Category Desc]to the ProductSubcategorytable and then we will add Category desc and subcategory name from theProductSubcategorytable to the Producttable:

    1. Open QlikViewEssentials_Chap3.qvw.

    2. Invoke the script editor by pressing Ctrl+ E.

    3. Navigate to the Dimensionstab and cut the Product Categoryload script

    and paste it in the Mappingtab.4. The mapping load of Product Categorywill appear as follows:

  • 7/25/2019 QlikView Essentials - Sample Chapter

    11/21

    Optimizing Your Data Model

    [44 ]

    5. Navigate to the Dimensionstab. Go to the last line of theProductSubCategoryload script and useApplyMapto add[Category Desc]to the ProductSubcategory.

    6. Save and execute your script. Review your data model in Table Viewer to seethat the Product Categorytable is removed and Category Descis added tothe ProductSubcategorytable.

    Mapping load ProductSubcategory tableUse mapping load with the ProductSubcategorytable to get the subcategory name:

    1. Navigate to the Dimensionstab and cut the ProductSubcategoryloadscript and paste it in the Mappingtab.

    2. The mapping load of ProductSubcategoryfor SubCategoryNameand[Category Desc]will appear as follows:

  • 7/25/2019 QlikView Essentials - Sample Chapter

    12/21

    Chapter 3

    [45 ]

    3. Navigate to the Dimensionstab and go to the last line of the Productload script. UseApplyMapto add SubCategoryNameand CategoryNameto the Producttable.ApplyMapstatements in the Producttable will appearas follows:

    4. Save and load the script. View your data model in Table Viewer.The ProductSubcategorytable is removed and SubCategoryNameand CategoryNameis added to the Producttable.

    Mapping load CountryRegion_InlineUse mapping load to get the CountryRegion_Descfrom CountryRegion_Inlineand include it in the Customerstable:

    1. The CountryRegion_Inlinetable can also be converted to the mapping table.

    2. Navigate to the Inlinetab and cut the CountryRegion_Inlineload scriptand paste it in the Mappingtab.

    3. The mapping load script for CountryRegionwill appear as follows:

    4. Navigate to the Dimensionstab. Go to the load script of the Customerstableand, in the last line, useApplyMapas follows:

    5. Save and load the script.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    13/21

    Optimizing Your Data Model

    [46 ]

    6. Review the data model in Table Viewer. The data model so far will appear asfollows. It is much cleaner with fewer tables.

    ConcatenationAnother 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 Allin SQL.It appends rows from one table to another. The result of concatenation between twotables (Table1and Table2,for example) is that a new table contains the sum of thenumbers of records in Table1and Table2. Concatenate is used when you have twofact tables in your data model. Two fact tables are not good for your data model. Youcan combine them using concatenate or link tables. Link tables are explained in thenext chapter.

    Concatenate is also useful when you have to combine two tables with similarstructures. Say, for example, your organization has an Employeetable that stores

    employee data. Your organization buys another company and now wants to mergethe details of the employees of this new company with the existing Employeetable.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    14/21

    Chapter 3

    [47 ]

    Let's explore different concatenation options:

    Automatic concatenation: If the field names and the number of fields in twoor more tables are exactly the same, QlikView will automatically concatenatethe 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 forceconcatenation by the use of Concatenatekeyword.

    No concatenate: If the field names and the number of fields in two ormore tables are exactly the same, QlikView will automatically concatenatethem but you can avoid such automatic concatenation by using theNoConcatenatekeyword.

    Concatenation exampleCreate an Inlinetable in QlikView to understand the concept of concatenation:

    Automatic Concatenation1. Navigate to the Inlinetab.

    2. Create two Inlinetables as shown in the following:

    3. Save and reload the script.

    4. View the data model in Table Viewer. You will see only one table with sixrows. This is because Table2automatically concatenated with Table1.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    15/21

    Optimizing Your Data Model

    [48 ]

    NoConcatenateUse the same script and add NoConcatenatebetween the two load scripts:

    In Table View you will see two tables, Table1and Table2. You will see that thesynthetic key between them, as column names in the tables, are the same.

    Forced concatenationTo test force concatenation, comment the previous Table1and Table2load scripts.

    1. Now create two tables with different columns and use the Concatenatekeyword 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.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    16/21

    Chapter 3

    [49 ]

    JoinsJoins in QlikView are similar to joins in SQL. Joins between two tables always resultin one table. With joins, the columns of the two tables are affected. Joins are explicitlymade 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 thoserecords 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 onlythose records from the first table that match a record in the second table arekept.

    Outer join or join: Records from both the tables will be stored and, wherepossible, records will be matched.

    Use Joins.qvwto practice different kinds of joins andconcatenate options. It is located in yourAppsfolder.

    Join Orders and Order DetailThe Orders and Order Detailtables will be joined because an optimized datamodel should have only one fact table.

    We will use left join between the tables:

    1. Use the QlikViewEssentials_Chap3.qvw. Navigate to the Orderstab inyour script editor.

    2. After the load scripts of the Orderstable, type left join (Orders).

    3. Comment the [Order Detail]table name as this table name will beirrelevant now.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    17/21

    Optimizing Your Data Model

    [50 ]

    4. Your updated script will appear as follows:

    5. Observe the data model in Table Viewer and you will see the OrdersandOrder Detailtables have combined into one table, Orders.

    Left join SalesPersonTo further optimize your data model, left join SalesPersonwith the Orderstable:

    1. Navigate to the EmployeesTab. Go to the SalesPersonload script.

    2. In the empty space before the load statement, type left join (Orders).

    3. This will left join Ordersand SalesPerson. It is good practice to type thetable name with left join otherwise it will left join with the previously loaded

    table script.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    18/21

    Chapter 3

    [51 ]

    4. Save and reload.

    5. Observe the Orderstable in the Table Viewer. SalesPerson NameandSalesPersonTitlehave been added.

    Aggregating dataWe have combined the Ordersand Order Detailtables; now it is time to find thesales amount for each of these orders by aggregating the data by OrderID:

    1. Use QlikViewEssentials_Chap3.qvw. Navigate to the Orderstab in yourscript editor.

    2. Navigate to the empty space after the Order Detailload statement.

    3. Perform "resident load" from the Orderstable and aggregate using the GroupByfunction. Resident load is used here as the Orderstable is already loadedin the script and we can reuse the same table using resident load.

    4. It will be better to keep[Order Sales Amt]

    in theOrders

    table as it is at theOrder level. To achieve this, go to the empty space above the load statementand type left join(Orders).

    5. Your script should appear as the following:

    Concatenating the new Employees tableAs the QlikView development was progressing, Adventure Works Inc. acquireda new company. Now they want to merge the new company's employees into theAdventure Works' Employeestable.

    This can be best achieved by using Concatenate, since we know that two tableswith the same structure get automatically concatenated. Even if the structure of

    NewEmployeesis not the same, we should make it the same so that it concatenateswith Employees.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    19/21

    Optimizing Your Data Model

    [52 ]

    The new employee file structure is similar to the Employeestable loaded in QlikView.

    This new employee file NewEmployees.xlsxis also located in the same location:

    1. Navigate to the Employeestab in QlikViewEssentials_Chap3.qvw.

    2. Go to the empty space after the SalesPersonload script.

    3. Click on Table Filesand browse to NewEmployees.xlsx, which is locatedunder C:\QlikViewEssentials\Data. Make sure to select Embedded labelsunder Labelswhile selecting the file.

    4. Remove the directory. Save and reload your script. You will observe justone table, Employees, in the data model and it will have records of bothEmployeesand NewEmployees.

    5. The script of the NewEmployeestable will appear as the following:

  • 7/25/2019 QlikView Essentials - Sample Chapter

    20/21

    Chapter 3

    [53 ]

    Reviewing the final data modelBy applying the previous techniques, the data model is being converted into astar schema.

    SummaryQlikView 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 schemaand converted our previously created data model into a star schema by usingmapping loads, joins, and concatenation.

    In the next chapter, we will learn about data modeling challenges, which areresolved by using cross tables, link tables, and the master calendar. You will alsolearn about handling slowly changing dimensions using the Interval Matchfunction. Finally we will use QVDs to read and write our data model tables.

  • 7/25/2019 QlikView Essentials - Sample Chapter

    21/21

    Where to buy this bookYou can buy QlikView Essentials from thePackt Publishing website.

    Alternatively, you can buy the book from Amazon, BN.com, Computer Manuals and most internetbook retailers.

    Click herefor ordering and shipping details.

    www.PacktPub.com

    Stay Connected:

    Get more information QlikView Essentials

    https://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/books/info/packt/ordering/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/books/info/packt/ordering/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.linkedin.com/company/packt-publishinghttps://plus.google.com/+packtpublishinghttps://www.facebook.com/PacktPub/https://twitter.com/PacktPubhttps://www.packtpub.com/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/books/info/packt/ordering/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapterhttps://www.packtpub.com/big-data-and-business-intelligence/qlikview-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapter