Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

nsnybs21qv
New Contributor II

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

Tags (1)
1 Solution

Accepted Solutions

Re: If statement in load script

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'));

3 Replies

Re: If statement in load script

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.....



nsnybs21qv
New Contributor II

Re: If statement in load script

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?

Re: If statement in load script

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'));

Community Browser