You are on page 1of 7

Learning module: Combining Tables-Mapping

Exercise - INSTRUCTIONS
Using the files in the Example Download section on the right and the instructions Example Download
below, you can practice combining tables in QlikView using the MAPPING prefix.
The example files provided for this
exercise contain information about
combining tables using mapping.

Basic Setup They are located in a zip archive,


available for download from the
course site. Extract the files from
the zip archive and place them in a
Open the QlikView Document convenient location on your local
hard drive.
 Launch QlikView and click the Open button on the toolbar
The Microsoft Access database
 Browse to the location where you have stored the CombiningTables- and QlikView document used in
Mapping_Practice.qvw document this exercise are:

 Open the CombiningTables-Mapping_Practice.qvw document CombiningTables_Practice.mdb


This file contains fictitious data
about a couple of famous rock
bands, including musician names,
instruments they play, where they
are from, and so on.
Open the Edit Script Dialog CombiningTables-
Mapping_Practice.qvw
 Click Edit Script on the toolbar

o Note: There should be three tabs of script in the Edit Script


dialog: Main, Facts, and Dimensions.

 Inspect the Main tab

o Note: There should be an OLEDB CONNECT32 statement

 Remove the OLEDB CONNECT32 statement


 Use the Connect button to recreate the connection statement, browsing to where you stored
CombiningTables_practice.mdb
 Click Reload

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik® Sense, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Mapping Bands’ City of Origin

No City of Origin for Queen

 Close Edit Script dialog and view sheet, Bands and Origins

 Select Led Zeppelin. What is the associated city of origin?


(Answer: London)

 Select Queen. What is the associated city of origin?


(Answer: There is no city in the OriginName list box that is associated with Queen)

 The reason for this is that, in the Bands table, Queen has no OriginID value. This can be seen by
previewing the Bands table in the Table Viewer.

 It can also be seen in the table box on the Bands and Origins tab in sheet view.
Note: NULLs don’t appear in list boxes.

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik Sense®, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Exercise instructions | page 2
Map OriginName to the Bands table

We will combine the small Origins table with the Bands table, with the immediate benefit of being able to
create a default OriginName that will appear in list boxes for any band where their city of origin is missing
from our database.

Create Mapping Table

 Open the Edit Script dialog and add a new tab, name it Mapping, and position it to immediately
follow Main

 In the Dimensions tab, cut the whole script block for the Origins table, including the comment,
LOAD and SQL SELECT statements to the clipboard

 Paste the contents of the clipboard into the Mapping tab. Consider how you would change the
following script in order to turn this into a mapping table.

 Ensure table has two fields only and the first field is the lookup field

 Type the MAPPING prefix before the LOAD statement

 Add suffix, “_map”, to the table name

 Copy the table name. You’ll need it in a moment.

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik Sense®, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Exercise instructions | page 3
Use ApplyMap()

 In the Dimensions tab, use the ApplyMap() function in the Bands table LOAD statement,
remembering to paste the table name from the clipboard to ensure it is spelled correctly The
script should look like this:

 Click Reload

 Inspect the Table Viewer

The scrollbar on the Bands table indicates that it has gained a new field.

 Preview the Bands table. Does the OriginID field serve us in any useful way?
(Answer: No. We can drop it and not lose any information or table association.

 Optional: Return to the Edit Script Dialog and add the following below the Bands LOAD block to
drop the field, OriginID:

 Click Reload

 Return to the Bands and Origins sheet. Have the OriginName list box contents changed?
(Answer: There is a new item, “Unknown City”)

 Name a benefit of having this new OriginName of UnknownCity.


(Answer: It can be selected to see all bands whose city of origin is missing)

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik Sense®, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Exercise instructions | page 4
Mapping Musicians’ Primary Instrument

Pete Townsend’s Instruments

 Open the Musicians and Instruments sheet in sheet view. Clear all selections, if necessary.

 How many instruments does Pete Townsend play?


(Answer: 4)

 If requirements state that we should display only one instrument for each musician, say their
primary instrument, MAPPING would be an ideal table-combining solution. In that case, one
technical requirement for the multi-instrumentalists would be that the mapping table loads the
instruments in a certain order. For our example, we’ll assume that the first instrument listed is that
musician’s primary instrument – for Pete Townsend, that would be a guitar.

Map Instrument to Musicians table

Create Mapping Table

 Open Table Viewer and inspect the MusicianInstruments and Musicians tables.

 MusicianInstruments, being a two-field table comprising of a look-up and corresponding value, is


a good candidate to be a mapping table.

 Close the Table Viewer and open the Edit Script dialog.

 In the Dimensions tab, cut the whole script block for the MusicianInstruments table, including the
comment, LOAD and SQL SELECT statements to the clipboard

 Paste the contents of the clipboard into the Mapping tab below the Origins_map table, leaving a
few blank lines to aid readability.

 Add the MAPPING prefix and modify the table name to indicate that it is a mapping table.

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik Sense®, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Exercise instructions | page 5
 Are the two fields in the correct order for a mapping table?
(Answer: No. Instrument appears first but it cannot be used as a lookup field.)
 Reverse the order of the two fields in the load statement placing MusicianID first, so that it can be
used as the lookup field in the ApplyMap() function

 Copy the table name. You’ll need it in a moment

Use ApplyMap()

 In the Dimensions tab, use the ApplyMap() function in the Musicians table LOAD statement,
remembering to paste the table name from the clipboard to ensure it is spelled correctly

 Click Reload

 Inspect the Table Viewer

What does the scrollbar on the Musicians table indicate?


(Answer: The table has gained a new field)

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik Sense®, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Exercise instructions | page 6
 What happened to the MusicianInstruments table?
(Answer: It was dropped at the end of script execution)

 Return to the Musicians and Instruments sheet. How have the Musician and Instrument table box
contents changed?
(Answer: Only one instrument is now listed for each musician)

©2016 QlikTech International AB. All rights reserved. Qlik®, Qlik Sense®, QlikView®, QlikTech®, Qlik® Cloud, Qlik® DataMarket, Qlik® Analytics Platform and the Qlik logos
are trademarks of QlikTech International AB which have been registered in multiple countries. Other marks and logos mentioned herein are trademarks or registered trademarks
of their respective owners. Use of any and all of the foregoing is subject to the written approval of Qlik.
Exercise instructions | page 7

You might also like