Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

apply map

can someone please help in explaining applymap functionwith example,why we use it,how it works,

4 Replies
Anonymous
Not applicable
Author

Hi

The MAPPING statement provides an alternative to the JOIN statement in a very specific scenario: when you want to replace a single key value with a value from a lookup (mapping) table.

We prefix ' Mapping' to the load statement to tell Qlikview that a table is a mapping table.

The mapping table is called with the 'Applymap()' function


Sample:


MapTable:

Mapping

LOAD * Inline

[

RegionName,RegionCode

Asia,AS

Europe,Eur

MEA,ME

];

Test:

LOAD RegionName,

ApplyMap('MapTable',RegionName,'N/A')

Resident main;

Drop table MapTable;

Thanks,

Anonymous
Not applicable
Author

whats the result of the above statement?

Anonymous
Not applicable
Author

Hi,

PFA to observe the result produced by apply Map.

Thanks

captain89
Creator
Creator

Hi,

it's very similar to the V.LOOKUP function in excel.

For example if you have two tables like this in your database:

Inventory:

Code, Quantity

a001, 100

a002,  50

a003,  70

Products:

Code, Description

a001, first code

a002, second code

you can join them using Code but if you create a table like this:

Code, Quantity, Description

a001, 100, first code

a002,  50, second code

a003, 70, -


but you get a null value in the description field... and you can't select it


if you use applymap you can put a value in the description field:


map_description:

mapping load Code, Description resident Products;

Inventory:

load

Code,

Quantity,

Applymap('map_description, Code, 'not found') as Decription.

applymap is far better.. in this case you can drop the Product table and your database is simpler and less CPU expensive...

In this way you can select "not found" values without any problem.

The only problem of applymap comes when your mapping table isn't indexed.

If you have a situation like this:

Product:

Code, Description

a001, first code

a002, second code

a002, third code

if you have duplicate values applymap put the first one. Joins are better in this case because the error is visible early.