Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
is the first endif needed?
if ... then
do something
if... then
do something
else
do something
endif
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.
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.
'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?
Does anyone have any other ideas?
Thanks
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.
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.
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.
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