Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
BI_Dev
Creator II
Creator II

Creating field based on the match

Hi - I have data as below

ID Name
1 ABC
1  
2 xyz
3  

Here I have ID and Name columns, but I want to create a key column where if the ID has a Name associated I want to Concatenate ID & Name, if and ID doesn't have a name, it will be Just ID as below.

KEY
1-ABC
2-XYZ
3

I tried below but doesn't work.

Load 

ID, NAME,

IF(LEN(Name)>0, ID &'-'&Name , ID as KEY

From...

 

Any thoughts pls.

Labels (5)
2 Solutions

Accepted Solutions
MarcoWedel

IF(LEN(Name)>0, ID &'-'&Name , ID) as KEY

View solution in original post

vinieme12
Champion III
Champion III

As @MarcoWedel suggested, you can do this in a single load

 

Temp:
LOAD 
ID
,Name
,IF(LEN(Name)>0, ID &'-'&Name , ID) as KEY
 Inline[
ID,Name
1,ABC
1,
2,xyz
3,
];

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

3 Replies
MarcoWedel

IF(LEN(Name)>0, ID &'-'&Name , ID) as KEY

BrunPierre
Partner - Master
Partner - Master

Temp:
LOAD * Inline[
ID,Name
1,ABC
1,
2,xyz
3,
];

NoConcatenate
Table:
LOAD ID,
MaxString(IF(Len((Name))>0,ID &'-'&Name,Text(ID))) as KEY

Resident Temp
Group By ID;
DROP Table Temp;

DROP Field ID From Table;

EXIT SCRIPT;

BrunPierre_0-1667249089677.png

vinieme12
Champion III
Champion III

As @MarcoWedel suggested, you can do this in a single load

 

Temp:
LOAD 
ID
,Name
,IF(LEN(Name)>0, ID &'-'&Name , ID) as KEY
 Inline[
ID,Name
1,ABC
1,
2,xyz
3,
];

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.