Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
DestinedTale
Contributor II
Contributor II

Qlikview If statement not working

Hi, I have a table with field batch id with many id including 20200523. So i want to do in such a way that if the count of test 2 is 1 because it is equal to test, then it will exit script. But seems like it doesn't work as it will continue on the else portion. 

 

let test = Date(20200523, 'YYYYMMDD');

LET test2 = (Count(if([BATCH_ID]= $(test), 1, 0)));

if test2=1 then
TRACE( Condition is valid);
EXIT Script;
ELSE

continue on the other part of the script

Labels (3)
1 Solution

Accepted Solutions
Taoufiq_Zarra

let test = Date(today()-1,'YYYYMMDD');


tmp:
load count(BATCH_ID) as Ctmp resident BAD_TPUT where BATCH_ID=$(test);

LET test2 = if(isnull(FieldValue('Ctmp',1)),0,FieldValue('Ctmp',1));

drop table tmp;

if $(test2)>1 then
trace --- buzzz ----;
Exit script
else

 

or share your file

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉

View solution in original post

11 Replies
Taoufiq_Zarra

Hi @DestinedTale 

changes to be expecte, for example :

let test = Date#(20200523, 'YYYYMMDD');

$(test2)

I suggest the following example :

Data:

load * inline [
BATCH_ID,A,B
20200523,1,5
20200523,2,6
20200525,3,7
20200526,4,8
];


let test = Date#(20200523, 'YYYYMMDD');

tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=$(test);

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;


if $(test2)=1 then
TRACE .... ;

ELSE

.....

 

Regards,
Taoufiq ZARRA

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

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

Hi, i did this based on your suggestion but it don't seems to hit the error and continue on the else section

Data:

load * inline [
BATCH_ID,A,B
20200523,1,5
20200523,2,6
20200525,3,7
20200526,4,8
];


let test = Date#(20200523, 'YYYYMMDD');

tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=$(test);

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;


if $(test2)=1 then
SET TriggerError;

ELSE

Taoufiq_Zarra

@DestinedTale 

because in Data the value of test2 is 2 (count of BATCH_ID(20200523))

suppose I have this input data :

Data:

load * inline [
BATCH_ID,A,B
20200523,2,6
20200525,3,7
20200526,4,8
];


let test = Date#(20200523, 'YYYYMMDD');

tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=$(test);

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;


if $(test2)=1 then
SET TriggerError;

 

the output is :

Taoufiq_ZARRA_0-1593600133545.png

so it doesn't go to ELSE

Regards,
Taoufiq ZARRA

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

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

Currently my script is 

Data:

load * inline [
BATCH_ID,A,B
20200523,2,6
20200525,3,7
20200526,4,8
];


let test = Date#(20200523, 'YYYYMMDD');

tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=$(test);

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;

if $(test2)=1 then
SET TriggerError;

else

but the error is not coming out for me. it just finished running the script. Did i miss out some settings in qlikview? 

2020-07-01 10:50:19 0103 Data:
2020-07-01 10:50:19 0104
2020-07-01 10:50:19 0105 load * inline [
2020-07-01 10:50:19 0106 BATCH_ID,A,B
2020-07-01 10:50:19 0107 20200523,2,6
2020-07-01 10:50:19 0108 20200525,3,7
2020-07-01 10:50:19 0109 20200526,4,8
2020-07-01 10:50:19 0110 ]
2020-07-01 10:50:19 3 fields found: BATCH_ID, A, B,
2020-07-01 10:50:19 3 lines fetched
2020-07-01 10:50:19 0113 let test = Date#(20200523, 'YYYYMMDD')
2020-07-01 10:50:19 0115 tmp:
2020-07-01 10:50:19 0116 load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=20200523
2020-07-01 10:50:19 1 fields found: Ctmp,
2020-07-01 10:50:19 1 lines fetched
2020-07-01 10:50:19 0118 LET test2 = FieldValue('Ctmp',1)
2020-07-01 10:50:19 0120 drop table tmp
2020-07-01 10:50:19 0122 if 1=1 then
2020-07-01 10:50:19 0123 SET TriggerError
2020-07-01 10:50:19 0125 else
2020-07-01 10:50:19 Execution finished.

 

Taoufiq_Zarra

can you share your file

attached my qlikview file

Regards,
Taoufiq ZARRA

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

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

hi, i managed to get it to work using the below code. Thanks for helping. 

tmp:
load count(BATCH_ID) as Ctmp resident BAD_TPUT where BATCH_ID=$(test);

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;

if $(test2)>1 then
trace --- buzzz ----;
Exit script;
else

Would like to check with you if i want to count on resident data table where batch_id = system-1, what is the right way to do it? 

tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=sysdate-1;

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;

if $(test2)>1 then
trace --- buzzz ----;
Exit script;
else

Taoufiq_Zarra

Maye be

tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=Date(today()-1,'YYYYMMDD');

LET test2 = FieldValue('Ctmp',1);;

drop table tmp;

if $(test2)>1 then
trace --- buzzz ----;
Exit script;
else
Regards,
Taoufiq ZARRA

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

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

hi, i have this error 

Unexpected token: '>', expected one of: '(', 'ZTestw_z', 'OPERATOR_PLUS', 'OPERATOR_MINUS', 'not', 'bitnot', 'LITERAL_NUMBER', ...

if >>>>>>><<<<<<1 then

for this code 

load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=Date(today()-1,'YYYYMMDD');

 

Taoufiq_Zarra

let test = Date(today()-1,'YYYYMMDD');
tmp:
load count(BATCH_ID) as Ctmp resident Data where BATCH_ID=$(test);

....
Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉