Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

nested if then control statement

Hello everyone,

I want to nest the if...then statement like

if ... then

     do something

     if... then

          do something

     endif

else

     do something

endif

The problem is: there are two endifs and qlikview stops at the first one and doesn't go futher. Does anyone have a solution for this issue?

Many thanks in advance

14 Replies
adamwilson
Partner - Creator
Partner - Creator

is the first endif needed?

if ... then

     do something

     if... then

          do something

else

     do something

endif

nagaiank
Specialist III
Specialist III

Here is an extract from Qlikview Reference Manual. If you follow the syntax, it will work.

The syntax is:

if condition then

[ statements ]

{ elseif condition then

[ statements ] }

[ else

[ statements ] ]

end if

Where:

condition is a logical expression which can be evaluated as true or false.

statements is any group of one or more QlikView script statements.

Since the if..then statement is a control statement and as such is ended with either a semicolon or end-of-line,

each of its four possible clauses (if..then, elseif..then, else and end if) must not cross a line boundary.

Not applicable
Author

Yes, it is.

I actually have a elseif for the inner if...then, and qv stops by the elseif, so I remove it and qv stops by the first endif.

Not applicable
Author

'each of its four possible clauses (if..then, elseif..then, else and end if) must not cross a line boundary.'

Well I didn't, I wrote each of them just in a line.

Does it mean that I cann't use nested if...then statement in qv?

Not applicable
Author

Does anyone have any other ideas?

Thanks

flipside
Partner - Specialist II
Partner - Specialist II

Are you wanting the "do something" after the else statement to execute and the script is only running the "if .. then" statement before it because if so that looks like it is working correctly.  Perhaps post your actual script.

Not applicable
Author

The syntax seems to be correct for me. I really don't understand, why it doesn't work.Especially how can I let qv know that there are two if...then statements, they have nothing to do with each other.

Not applicable
Author

Here is an example of a nested If in Qlikview.

IF(Category = 'A',

       IF(Country = 'AUS', 'Australia',

       IF(Country = 'CHN' and Sub = 'HK', 'Hong Kong (SAR)'

       , 'Unknown Asia Pacific'))

, IF(Category = 'B',

       IF(Country = 'GER', 'Germany',

       IF(Country = 'FRA', 'France'

       , 'Unknown Europe'))

, 'Unknown'))

 

This is:

If

(

    If

    ElseIf  

    Else

)

ElseIf

(

    If

    ElseIf

    Else

)

Else

Be careful of the commas, they trip you up when doing nested IF, it is best to follow a structure that you find comfortable and stick to it.

flipside
Partner - Specialist II
Partner - Specialist II

Have you got multiple steps within your if statement, ensure they are terminated with semi-colons correctly.

If Day(Now())=1 or Day(Now())=2 or Day(Now())=3 then

    LET vSuffix = '.qvd';

    Store Profile into '..\Profile'$(vSuffix) (qvd);

Else

    LET vSuffix = '.txt';

    Store Profile into '..\Profile'$(vSuffix) (txt);

End If;

Other than that, please post your code.

flipside