Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator III
Creator III

Nesting IF THEN ENDIF

Is it possible to nest IF THEN ENDIF statements?  I am having an issue doing it in my app:

IF condition1 THEN

IF condition2 THEN

     do something

ENDIF     //this should end condition 2 becasue it is nested.

ENDIF     //this should end condition 1 because it is the outside set

This seems to create an issue when condition 1 is not met due to an extra ENDIF it can't handle.  This leads me to believe it is using the first ENDIF statement rather than the second.

Anybody have ideas on getting this to work?

3 Replies
Highlighted
Not applicable

Nesting IF THEN ENDIF

Yup nesting IFs is certainly possible. You could try using and AND to combine the IFs together like this:

IF Field1='ABC' AND Field2=25 THEN

END IF

Highlighted
Creator III
Creator III

Nesting IF THEN ENDIF

Well so really they are not "nested".  A nested IF statement would exist completely inside another.  But the approachg you suggested does solve my problem.  Thanks for the assist!

Highlighted
Not applicable

Re: Nesting IF THEN ENDIF

True, using the AND isn't really a nested IF. But true nested IFs should work perfectly and I've done so more times than I can count. No idea why they aren't working for you. I just rand this and it worked as expected:

IF 1=1 THEN

    IF 1=1 THEN

        trace hello world;

    ENDIF

ENDIF

Out of interest, try changing ENDIF for END IF (with a space) as I normally use the latter and it wouldn't be the first time I've seen a strange bug like that in QV.