Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

If statement in load script

Hi

I'm use an "if statement" to check a condition in load script, but I got this syntax error 

this is the if statement:

IF count([Calendar year])= 0 THEN

DROP TABLE Data;

Else

Load data…

ENDIF

The error I got is :

Unexpected token: '=', expected: 'THEN'

IF (count([Calendar year])>>>>>>=<<<<<< 0) THEN

I also tried to put count([Calendar year])= 0 inside (), but still getting the same error.

any idea why?

Thanks

Yvonne

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Change variable and assign vTotalYear to random value when Calendar Year field not exists.

Let vTotalYear = IF(Len(Trim(Peek('TotalYear',0,'Temp')))=0,100000,Peek('TotalYear',0,'Temp'));

View solution in original post

3 Replies
MK_QSL
MVP
MVP

You can do something like below..

First load your original table...

Temp:

Load Count(Distinct Year) as TotalYear;

Load FieldValue('Calendar year',RecNo()) as Year

AutoGenerate FieldValueCount('Calendar year');


Let vTotalYear = Peek('TotalYear',0,'Temp');

Drop Table Temp;


IF vTotalYear = 0 THEN

Drop Table Data;

Else

Load your data.....



Anonymous
Not applicable
Author

Hi Manish

Thanks for your code. I think it's working when  vTotalYear = 0 is tested true. However, it's possible that there's the field 'Calendar year' doesn't exist. and under that condition, it should go to else statement.. But the code is giving a field not found error. Any idea how to adjust the code?

MK_QSL
MVP
MVP

Change variable and assign vTotalYear to random value when Calendar Year field not exists.

Let vTotalYear = IF(Len(Trim(Peek('TotalYear',0,'Temp')))=0,100000,Peek('TotalYear',0,'Temp'));