Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
hamid
Partner - Contributor II
Partner - Contributor II

Nested IF Else Statement

Hi,

Why the script bellow is failling in qlik sense , i'm expecting it returns "Step 1"

if 1=1 then
    If 1=1 then
      Trace Step 1;
     else
        Trace Step 2;
     End If
Else
Trace Step 3;
End If;

Labels (2)
1 Solution

Accepted Solutions
steeefan
Luminary
Luminary

Works as expected:

If 1=1 then
  If 1=1 then
    Trace Step 1;
  else
    Trace Step 2;
  End If
Else
  Trace Step 3;
End If;

steeefan_0-1714740934164.png

Make sure you don't have anything else before it that interferes. Based on the error message, I believe this to be the case.

In your screenshot, you can actually see "Trace 1" in the log.

View solution in original post

7 Replies
BenjaminT
Partner - Creator
Partner - Creator

This does trace 'Step 1' to the reload log. Is that what you want it to do?

Fabiano_Martino_Intelco
Partner - Creator II
Partner - Creator II

hi @hamid 

the script returns an error or it completes but with an unexpected result?

Regards

hamid
Partner - Contributor II
Partner - Contributor II
Author

Hello,

it returns an error :

The following error occurred:
The control statement is not correctly matched with its corresponding start statement
 
The error occurred here:
Else
hamid
Partner - Contributor II
Partner - Contributor II
Author

I attched the error message, want to figure out with you what"s the issue of using the syntaxe 

steeefan
Luminary
Luminary

Works as expected:

If 1=1 then
  If 1=1 then
    Trace Step 1;
  else
    Trace Step 2;
  End If
Else
  Trace Step 3;
End If;

steeefan_0-1714740934164.png

Make sure you don't have anything else before it that interferes. Based on the error message, I believe this to be the case.

In your screenshot, you can actually see "Trace 1" in the log.

Fabiano_Martino_Intelco
Partner - Creator II
Partner - Creator II

Hi @hamid 

do you have an Exit Script; instruction followed by some other code?

Regards

hamid
Partner - Contributor II
Partner - Contributor II
Author

The script is working now, i pasted it in a new app, it seems that it was taking into account the other parts of the script that was after the "Exit script" !!

Ok ! lesson learned 🙂 thank you for you support all.