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

How to create IF statement to make field from another field.

kush141087its.anandrjsantoniotimanloveisfail serj_shu

Hi,

I have the following data:

SKU CodeCategory
001AA
002BB
003CC
004DD
005EE
006FF

Now I want to create a field say "Channel" with values 'X4' and 'X6' like this:


Load

SKU Code,

If(Wildmatch (Category,'AA', 'BB', 'CC','DD'),'X4',

If(Wildmatch (Category,'AA', 'BB', 'CC','DD','EE','FF'),'X6')) as Channel


But this is not working. It is giving correct value of X4 but in case of X6 it is only considering values which are not covered in X4 i.e EE & FF only.


Please help.


Note: I cannot take two loads as it will multiple my data which happens to be SKU wise volume which I have to later show in a straight table where Category and Channel both will be dimensions. Basically the need for channel is to show sub totals on the basis of X4 & X6.

Thanks

Nick

1 Solution

Accepted Solutions
Kushal_Chawda

try like below

Data:

LOAD * Inline [

SKU ,Category

001 ,AA

002 ,BB

003 ,CC

004 ,DD

005 ,EE

006 ,FF

];

Link:

load distinct Category,

        'X4' as Channel

resident Data

where match (Category,'AA', 'BB', 'CC','DD');


Concatenate(Link)

load distinct Category,

        'X6' as Channel

resident Data

where match (Category,'AA', 'BB', 'CC','DD','EE','FF');

View solution in original post

5 Replies
Chanty4u
MVP
MVP

what is the result you want to see?

Chanty4u
MVP
MVP

May be try this

a:

load *,

if(match(Code,'AA','BB','CC','DD'),'x4',null()) as new ,

if(match(Code,'AA','BB','CC','DD','EE','FF'),'x6',null()) as new1;

LOAD * Inline [

SKU ,Code

001 ,AA

002 ,BB

003 ,CC

004 ,DD

005 ,EE

006 ,FF

];

exit SCRIPT;

nickjose7
Creator
Creator
Author

I want to see something like below:

Let our data be:

SKUCategoryVolume
001AA10
002BB20
003CC30
004DD40
005EE50
006FF60

Then the result should be like:

 

ChannelVolume
X4100
X6210
Kushal_Chawda

try like below

Data:

LOAD * Inline [

SKU ,Category

001 ,AA

002 ,BB

003 ,CC

004 ,DD

005 ,EE

006 ,FF

];

Link:

load distinct Category,

        'X4' as Channel

resident Data

where match (Category,'AA', 'BB', 'CC','DD');


Concatenate(Link)

load distinct Category,

        'X6' as Channel

resident Data

where match (Category,'AA', 'BB', 'CC','DD','EE','FF');

nickjose7
Creator
Creator
Author

Thanks Kushal. This works though I was looking for correction in the original IF statement if possible.