Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Charlz_1
Contributor II
Contributor II

If...then statement

Good day,

I want to create a new field "Label"

So I want to group the following data with if statement to create the "Label" field:

NIKE-986543, NIKE-776543, NIKE-098766, NIKE-445321

ADIDAS-587415, ADIDAS-866598

PUMA-694528, PUMA-007945, PUMA-377326

REDBAT-277539, REDBAT-800694 

Your help will be highly appreciated

Thanks.....

1 Solution

Accepted Solutions
Prathamesh_D
Partner - Contributor II
Partner - Contributor II

Hey 

You can do this by creating nested if statements - 

 

If( Match ( Code , '986543' , '776543' , '098766' , '445321') , 'NIKE',

    If( Match ( Code , '587415' , '866598') , 'ADIDAS' ,

        If( Match ( Code , '694528' , '007945' , '377326') , 'PUMA',

              If( Match ( Code , '277539' , '800694') , 'REDBAT' ))))  AS  Label

Thanks

 

View solution in original post

6 Replies
Taoufiq_Zarra

@Charlz_1  if I understood correctly, you can use :

PICK(WildMatch(Field,'*NIKE*','*ADIDAS*','*PUMA*'),'NIKE','ADIDAS','PUMA') as Label

example :

Test:
LOAD *,PICK(WildMatch(Field,'*NIKE*','*ADIDAS*','*PUMA*'),'NIKE','ADIDAS','PUMA') as Label INLINE [
Field
NIKE-986543
ADIDAS-587415
PUMA-694528

];

output:

Taoufiq_Zarra_0-1642170136304.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Charlz_1
Contributor II
Contributor II
Author

@Taoufiq_Zarra 

What about other data that appears under the same label?

kleman_emark
Partner - Contributor III
Partner - Contributor III

@Charlz_1 

The solution from  will assign the label value to all rows containing the defined text strings. So if there are 3 values in the same row; e.g. , PUMA-694528, PUMA-007945, PUMA-377326 -> this row will receive a value in field Label = 'PUMA'. Similarly all rows containing the string 'PUMA' will be labeled 'PUMA'.

If this solution is not suitable for your use case, it would help if you would provide same sample data (a few rows) and describe what you would like to achieve.

PrashantSangle

Hello @Charlz_1 ,

use subfield() for this

try like this

subfield(fieldName,"_",1) as Label

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Prathamesh_D
Partner - Contributor II
Partner - Contributor II

Hey 

You can do this by creating nested if statements - 

 

If( Match ( Code , '986543' , '776543' , '098766' , '445321') , 'NIKE',

    If( Match ( Code , '587415' , '866598') , 'ADIDAS' ,

        If( Match ( Code , '694528' , '007945' , '377326') , 'PUMA',

              If( Match ( Code , '277539' , '800694') , 'REDBAT' ))))  AS  Label

Thanks

 

Charlz_1
Contributor II
Contributor II
Author

Hi @Prathamesh_D 

Thanks a lot, it worked.