Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
srinivasa1
Creator II
Creator II

Apply Map

Hey any one has good example for apply map. as im first time using this feture

thx in advance.

16 Replies
Sokkorn
Master
Master

Hi Srinivasa,

Let take a look my script below:

[tmpData1]:

LOAD * INLINE [

F1,    F2

1,            100

2,            200

3,            300

4,            400

5,            500];

[Mapping1]:

MAPPING

LOAD * INLINE [

CusID,    CustName

1,    AA

2,    BB

3,    CC];

[TestApplyMap]:

LOAD

    F1    AS CustomerID,

    APPLYMAP('Mapping1',F1,'-')    AS CustomerName,

    F2    AS Amt

RESIDENT [tmpData1];

DROP TABLE [tmpData1]

Result:

CustomerIDCustomerNameAmt
1AA100
2BB200
3CC300
4-400
5-500

See more in attached file.

Hope this help you.

Regards,

Sokkorn

SunilChauhan
Champion II
Champion II

you can write mapping keyword and applymap in same table

ddo like below;

ta

tamp:
mapping
load *
resident Employee_Mail;
drop table Employee_Mail;
Employees_new:
Load *,
ApplyMap('tamp',EmployeeID) as Email
resident Employees;
drop table Employees;

shipment_tamp1:
mapping
load *
resident Shipments;
drop Table Shipments;
Temp_Order_Detail:
Load *,
ApplyMap('Shipments','Order_Line_Key') as Email
resident OrderDetail;
drop table OrderDetail;

Sunil Chauhan
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Batra,

It comes down to the third optional parameter of ApplyMap.  If this is omitted (as in the example for 4 above) then the value that is being used as the key is returned as the vaule where no match is found.  If a third parameter is provided this then this is used in the case of no match being found (as in the example for 5 above).

I go into detail on this here: http://bit.ly/kQcAZ5

- Steve

Not applicable

okey, it means if will ot mention third parameter in case of 5 thn it would display '5'  as in case of 4 it had done..

now its clear to me.

thank u so much sir

Not applicable

Hi sokkorn,

          I have a doubt. In ur table, u mention like ' - ' symbol. I tried this example without giving that symbol in mapping. Instead the symbol i got customerid again in the customername filed.. help me in this..

Not applicable

Hi Manimaran,

the '-' used in the above code is an optional keyword. If you dont use this then you will get the same value for those who does not exist in the mapping table.

Thanks & Best Regards,

Kuldeep Tak

Not applicable

ApplyMap( 'mapname', expr [ , defaultexpr ] )

Maps any expression on a previously loaded mapping table. Expr is

the expression whose result shall be mapped. Mapname is the name

of a mapping table previously loaded by a mapping load or mapping

select statement . The name must be quoted

with single quotes. Defaultexpr is an optional expression, which

will be used as default mapping value if the mapping table does not

contain any matching value for expr. If no default is provided, the

value of expr is returned as is.

SCRIPT EXPRESSIONS

421

IV

Examples:

// Assume the following mapping table

map1:

mapping load * inline [

x,y

1,one

2,two

3,three];

ApplyMap( 'map1' , MyVal ) returns 'two' if MyVal = 2

ApplyMap( 'map1' , MyVal ) returns 4 if MyVal = 4

ApplyMap( 'map1' , MyVal, 'x' )

returns 'x' if MyVal <> 1, 2 or 3

ApplyMap( 'map1' , MyVal, null() )

returns null if MyVal <> 1, 2 or 3

ApplyMap( 'map1' , MyVal, null() )

returns 'one' if MyVal = 1

Reference from Qlikview reference manual