Sunday 22 March 2015

Mapping and ApplyMap

Today I want to discuss how to use Mapping Tables in QlikView. 
Mapping Tables can be used in scenarios where code is used to get description. Mapping Tables should have only two columns.
In Qlikview it is always advisable to minimize the number of tables in the data model.

Suppose we've got two tables:
SalesTable:
OrderId, ProductId
1, 12
1, 13
3, 16
4, 22

and

ProductTable:
OrderId, ProductId
12, 12th
12, another one description
13, 13th
14, 14th
15, 15th
16, 16th
17, 17th

Load following script:
SalesTable:
Load *
Inline [
OrderId, ProductId
1, 12
1, 13
3, 16
4, 22
];

Product_map:
mapping LOAD * INLINE [
ProductId, Description
12, 12th
12, another one description
13, 13th
14, 14th
15, 15th
16, 16th
17, 17th
];

SalesFact:
LOAD *,
     ApplyMap('Product_map', ProductId, 'No data') as ProductDescription
     Resident SalesTable;
     
// This table is longer needed in the FactTable
DROP Table SalesTable;


In fact Map in QlikView is a pair of <type, mapped_type> with 1:1 relationship.
To get information from map we have to use ApplyMap function.

The ApplyMap function is used for mapping any expression to a previously loaded mapping table. The syntax is:

applymap('mapname', expr [ , defaultexpr ] ) 
where:
mapname is the name of a mapping table that has previously been created through the mapping load or the mapping select statement. Its name 
must be enclosed by single, straight Quotation Marks in Scripting. 
expr is the expression, the result of which should be mapped. 
defaultexpr is an optional expression which will be used as a default mapping value if the mapping table does not contain a matching value for expr. If no default value is given, the value of expr will be returned as is. 

Take a look at Product_map closer.
1. There is no information about product with id=22 and we see No data message 



2. I intentionally duplicated information about product with id=12 in the map.

Despite of this ApplyMap returns only one (first) value.

Generally ApplyMap works like VLookup.

Note:
Keyword Resident means loading data from previously loaded table (SalesTable);
After loading data from SalesTable we may drop this table bacause SalesTable is longer needed in the FactTable;
Copyright © 2015 Ruslan Goncharov

4 comments:

  1. Maxmunus Providing Free Webinar/Demo on Qlikview.Qlikview tutorial step to step process will help understanding QlikView tutorial in better way. also Qlikview tutorial pdf include each and every detail of QlikView basics for beginners.
    For Registration Contact:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: arun@maxmunus.com
    Contact No: +91- 9738507310, 080-41103383
    Company Website :- http://www.maxmunus.com

    ReplyDelete
  2. I really appreciate the information shared above. It’s of great help. MaxMunus provides Remote Support For Corporate and for Individuals. If anyoneis facing any issue in his project of #QLIKVIEW we can support them remotely , kindly Contact MaxMunus
    MaxMunus Offer World Class Industry best Consultant on# QLIKVIEW. We provide end to end Remote Support on Projects. MaxMunus is successfully doing remote support for countries like India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Saurabh
    MaxMunus
    E-mail: saurabh@maxmunus.com
    Skype id: saurabhmaxmunus
    Ph:(0) 8553576305/ 080 - 41103383
    www.MaxMunus.com

    ReplyDelete
  3. I really appreciate the information shared above. It’s of great help ON QlikView Training

    ReplyDelete
  4. The main motive of the Big data implementation services is to spread the knowledge so that they can give more big data engineers to the world.

    ReplyDelete