Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
cliff_clayman
Creator II
Creator II

Creating a new field value based on values from another field

I have a field, Collective Value, that I am trying to use the values for to create a new field, Collective PO.  The values in Collective Value are mixed, some are numeric and some are alphanumeric.  For example, 00, 1, 11, 21, 31, 11CD, 11FP, etc.  There are also blanks in some of the values.  Anything starts with a 1 or is blank I want to assign a value of 'N'.  Anything greater than a 1, I want to assign a 'Y' and anything that starts with a 0, I want to assign 'CO'.  Since the field is not numeric, what is the best method of doing this?

Labels (3)
1 Solution

Accepted Solutions
Surya
Creator II
Creator II

Hope its useful:

new:
load * inline [
sno,name,sal
00,sai,5000
01,nsa,344
03,asd,234
11,sadf,123
12,sad,134
16,gfh,345
15,rty,867
23,sdf,234
,dfg,23445
];


load *,if(WildMatch(sno,'0*'),'CO',
if(WildMatch(sno,'1*'),'N','Y')
) as newlist

resident new;

drop table new;

 

 

Thanks & Regards

SP

View solution in original post

4 Replies
asinha1991
Creator III
Creator III

simplest way I can think of

create a map

key_map:
Mapping Load * inline[
_key, _Value
0, CO
1, N
blank, N

]

and use this in your load

applymap('key_map',left(replace([Collective Value],'','blank',1)),'Y') as [Collective PO]

 

 

Surya
Creator II
Creator II

Hi Dear,

Give me your expected output.

 

 

 

Thanks & Regards

Surya

cliff_clayman
Creator II
Creator II
Author

 

Collective ValueCollective PO
00CO
1N
11N
11CDN
11FPN
21Y
31Y
Surya
Creator II
Creator II

Hope its useful:

new:
load * inline [
sno,name,sal
00,sai,5000
01,nsa,344
03,asd,234
11,sadf,123
12,sad,134
16,gfh,345
15,rty,867
23,sdf,234
,dfg,23445
];


load *,if(WildMatch(sno,'0*'),'CO',
if(WildMatch(sno,'1*'),'N','Y')
) as newlist

resident new;

drop table new;

 

 

Thanks & Regards

SP