Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
coloful_architect
Creator II
Creator II

date attributes management for changing dimension/name at loading scirpt

Hi experts.

so I am trying to do some data manipulation for change two products' name.

my simplified data structure looks like this. Each product has unique SKU under different group.

if I want to change two product (sku 7 and 😎 's group from D into C, what code I shall do at loading script?

Thanks 

Product SKUProduct Groupsales
1A935
2A134
3B666
4B915
5C530
6C165
7D542
8D660
2 Solutions

Accepted Solutions
anthonyj
Creator III
Creator III

Hi,

It seems one of your instructions turned into an emoji but I'm guessing you're referring to conditionally changing the 'D' to 'C' if the Product SKU is 7 or 8.

To do that you can use an 'if' condition with a match function such as below.

if(match([Product SKU],7,8), 'C', [Product Group]) as [Product Group]

This will return 'C' if the SKU is 7 or 8 and if not, will return the original value of [Product Group]

I hope this helps.

Regards

Anthony

View solution in original post

Coloful_Black
Contributor III
Contributor III

Try if + Match

 

 if (Match ([Field Name], value 1, value 2, value 3,  value you want to change, [Target Field Name]) as (Target Field Name)

 

in your case,

if (Match ([SKU], 7 ,8), 'C', [Product Group]) as [Product Group]

tricky part is that you dont need to worry the original value of D ...just input the new value you want to change

 

View solution in original post

5 Replies
anthonyj
Creator III
Creator III

Hi,

It seems one of your instructions turned into an emoji but I'm guessing you're referring to conditionally changing the 'D' to 'C' if the Product SKU is 7 or 8.

To do that you can use an 'if' condition with a match function such as below.

if(match([Product SKU],7,8), 'C', [Product Group]) as [Product Group]

This will return 'C' if the SKU is 7 or 8 and if not, will return the original value of [Product Group]

I hope this helps.

Regards

Anthony

Coloful_Black
Contributor III
Contributor III

Try if + Match

 

 if (Match ([Field Name], value 1, value 2, value 3,  value you want to change, [Target Field Name]) as (Target Field Name)

 

in your case,

if (Match ([SKU], 7 ,8), 'C', [Product Group]) as [Product Group]

tricky part is that you dont need to worry the original value of D ...just input the new value you want to change

 

coloful_architect
Creator II
Creator II
Author

Hi Anthony

a followed up question. now I have a bigger table like this 

without touching SKU, I want to change Flag on product group A, B , C with package type of bag from Yes to No

and also the flag on product group of C with package type of carton from Yes to No. 

Tried this with your logic ...but must have missed something....it wont return what I expect

if (Match([Product Group], 'A','B','C') or Match([Package Type],'BAG')

and ((Match ([Product Group], 'C') or Match ([Package Type]),'Carton')) , 'No', [Flag])as "Flag",

Product SKUProduct GroupsalesPackage TypeFlag
1A935boxYes
2A134bagYes
3B666cartonYes
4B915bagYes
5C530boxYes
6C165bagYes
7D542boxYes
8D660cartonYes
9E166bagYes
10E900boxYes
11F305cartonYes
12F526bagYes
13G700cartonYes
14G379boxYes
15H749bagYes
16H734cartonYes
17I590boxYes
18I594boxYes
coloful_architect
Creator II
Creator II
Author

Hi Coloful_black

a followed up question. now I have a bigger table like this 

without touching SKU, I want to change Flag on product group A, B , C with package type of bag from Yes to No

and also the flag on product group of C with package type of carton from Yes to No. 

Tried this with your logic ...but must have missed something....it wont return what I expect

if (Match([Product Group], 'A','B','C') or Match([Package Type],'BAG')

and ((Match ([Product Group], 'C') or Match ([Package Type]),'Carton')) , 'No', [Flag])as "Flag",

Product SKUProduct GroupsalesPackage TypeFlag
1A935boxYes
2A134bagYes
3B666cartonYes
4B915bagYes
5C530boxYes
6C165bagYes
7D542boxYes
8D660cartonYes
9E166bagYes
10E900boxYes
11F305cartonYes
12F526bagYes
13G700cartonYes
14G379boxYes
15H749bagYes
16H734cartonYes
17I590boxYes
18I594boxYes
anthonyj
Creator III
Creator III

Hi,
your First Condition is that the Product Group has to be 'A','B','C' AND the Package Type of 'BAG'. This means that you want these two conditions to be resolved together. You do this by wrapping the two conditions in brackets.
The Second Condition is 'C' AND 'CARTON' so you wrap both of these in brackets and join the two together with an 'OR'. The brackets are important because you're telling Qlik that the row has to be both Product Group and Package Type to be true.

So the condition would look like this:
(First Condition)
OR
(Second Condition) to be true;

The code would look like this:

if ( (Match([Product Group], 'A','B','C') and Match(upper([Package Type]),'BAG'))
or
(Match ([Product Group], 'C') and Match (upper([Package Type]),'CARTON'))
,'No', [Flag])

One other thing I noticed is that your search strings were not in the same case as the code you were using. Qlik is case sensitive and so a way you can future proof any potential changes in the contents of your data is to wrap the column in an UPPER( ) function. This will help normalise any potential differences in your column values and guard against any future changes as well.

Thanks

Anthony