Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
coloful_architect
Creator II
Creator II

change data value with conditions at load script (if match function)

Hi guys,

I have a table like this , wanna edit the flag field.

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 to make if/match with "and" /"or"...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",

and idea?

Product SKUProduct GroupsalesPackage TypeFlag
1A935boxYes
2A134bagNo
3B666cartonYes
4B915bagNo
5C530boxYes
6C165bagNo
7D542boxYes
8D660cartonYes
9E166bagYes
10E900boxYes
11F305cartonYes
12F526bagYes
13G700cartonYes
14G379boxYes
15H749bagYes
16H734cartonYes
17I590boxYes
18I594boxYes
4 Replies
pmaland
Contributor
Contributor

Match is case sensitive, try using mixmatch and see if that works.

coloful_architect
Creator II
Creator II
Author

well, tried. but still do not get preferred result. 

pmaland
Contributor
Contributor

What about adding a calculated field?  That way you can see a preview as you work on the formula.

pmaland_0-1628892951622.png

 

NageshSG
Partner - Contributor III
Partner - Contributor III

Hi

Ideally a mapping table with the business rule you have specified should work. You can then apply the same when loading the data table. Especially useful if data is very large.

Few things i noticed:

1. I assume the sample table above is the source data with the 'Flag' field already in place but you want to change the value based on the condition:

1. 1 I want to change Flag on product group A, B , C with package type of bag from Yes to No (Your sample data already shows the values as 'No'!)

1.2  and also the flag on product group of C with package type of carton from Yes to No.  (Your sample data has no combination Product C and package type as 'carton' !)

Anyhow, can you try the following script with your full data set. 

Sample script below:

FilterNewFlag:
// first flag
LOAD
FlagKey,
'No' as Flag;
Load distinct

[Product SKU]&[Product Group]&[Package Type] as FlagKey
FROM
[sample data.xlsx]
(ooxml, embedded labels, table is FlagUpdate)
where
(
(([Product Group] = 'A' or [Product Group] = 'B' or [Product Group] = 'C'))
and
lower([Package Type]) = 'bag'
)

;
// this second set concatenates to above
LOAD
FlagKey,
'No' as Flag;
Load distinct
[Product SKU]&[Product Group]&[Package Type] as FlagKey
FROM
[sample data.xlsx]
(ooxml, embedded labels, table is FlagUpdate)
where
[Product Group] = 'C' and lower([Package Type]) = 'carton'
;


mapNewFlag:
Mapping load
FlagKey,
Flag
Resident FilterNewFlag ;
DROP Table FilterNewFlag;

Data:
LOAD [Product SKU],
[Product Group],
sales,
[Package Type],
Flag,
ApplyMap('mapNewFlag',[Product SKU]&[Product Group]&[Package Type],Flag) as NewFlag
FROM
[sample data.xlsx]
(ooxml, embedded labels, table is FlagUpdate);