Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Map all values to one

Hi guys,

Recently I've faced a need to map all the possible incoming values to one value. And I failed.

Assume that you have a table of customers and you want to consider just a dozen of them. All the other customers should be renamed as Others, for example.

Is it possible to accomplish this task with mappings? Or is there another nice way except writing complicated conditional load scripts?

I would expect a map like this to work:

mapping load * inline [
x,y
Cust1,Customer 1
Cust2,Customer 2
*,Other customers];


But it doesn't. What would you suggest?

Thanks.

Valera

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Valera,
It is simpler than you think:


CustomerMap:
mapping load * inline [
x, y
Cust1,Customer1
Cust2,Customer2];
//
Table:
LOAD
...
applymap('CustomerMap', CustomerCode, 'Other') as Customer,
...
RESIDENT...;

If Customercode='Cust1', then you get Customer='Customer1'
If Customercode='Cust2', then you get Customer='Customer2'
In any other case, you get Customer='Other'.

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Valera,
It is simpler than you think:


CustomerMap:
mapping load * inline [
x, y
Cust1,Customer1
Cust2,Customer2];
//
Table:
LOAD
...
applymap('CustomerMap', CustomerCode, 'Other') as Customer,
...
RESIDENT...;

If Customercode='Cust1', then you get Customer='Customer1'
If Customercode='Cust2', then you get Customer='Customer2'
In any other case, you get Customer='Other'.

Anonymous
Not applicable
Author

Ah, this is the solution! 🙂

However, I was wondering if it was possible to do something the same with "map... using" structure. I am used to it and I wanted to find a solution with "map..using". Can it be done?

Thanks.

Valera

Anonymous
Not applicable
Author

Believe it or not, I've never used "map ... using". The applymap() works fine.