Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 SKU | Product Group | sales |
1 | A | 935 |
2 | A | 134 |
3 | B | 666 |
4 | B | 915 |
5 | C | 530 |
6 | C | 165 |
7 | D | 542 |
8 | D | 660 |
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
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
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
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
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 SKU | Product Group | sales | Package Type | Flag |
1 | A | 935 | box | Yes |
2 | A | 134 | bag | Yes |
3 | B | 666 | carton | Yes |
4 | B | 915 | bag | Yes |
5 | C | 530 | box | Yes |
6 | C | 165 | bag | Yes |
7 | D | 542 | box | Yes |
8 | D | 660 | carton | Yes |
9 | E | 166 | bag | Yes |
10 | E | 900 | box | Yes |
11 | F | 305 | carton | Yes |
12 | F | 526 | bag | Yes |
13 | G | 700 | carton | Yes |
14 | G | 379 | box | Yes |
15 | H | 749 | bag | Yes |
16 | H | 734 | carton | Yes |
17 | I | 590 | box | Yes |
18 | I | 594 | box | Yes |
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 SKU | Product Group | sales | Package Type | Flag |
1 | A | 935 | box | Yes |
2 | A | 134 | bag | Yes |
3 | B | 666 | carton | Yes |
4 | B | 915 | bag | Yes |
5 | C | 530 | box | Yes |
6 | C | 165 | bag | Yes |
7 | D | 542 | box | Yes |
8 | D | 660 | carton | Yes |
9 | E | 166 | bag | Yes |
10 | E | 900 | box | Yes |
11 | F | 305 | carton | Yes |
12 | F | 526 | bag | Yes |
13 | G | 700 | carton | Yes |
14 | G | 379 | box | Yes |
15 | H | 749 | bag | Yes |
16 | H | 734 | carton | Yes |
17 | I | 590 | box | Yes |
18 | I | 594 | box | Yes |
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