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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Syntax Help on setting variables

Can someone help me with syntax. There's something wrong here, but I don't know what it is:

LET vLastWeekLastYr = 52;
LET vCurrentWeekThisYr = 53;

If(
$(vCurrentWeekThisYr) > $(vLastWeekLastYr),
LET vCurrentWeek = $(vLastWeekLastYr),
LET vCurrentWeek = $(vCurrentWeekThisYr)
);

1 Solution

Accepted Solutions
Not applicable
Author

Script IF statements work differently than expression IF statments. Try this:

LET vLastWeekLastYr = 52;

LET vCurrentWeekThisYr = 53;

IF $(vCurrentWeekThisYr) > $(vLastWeekLastYr) THEN

LET vCurrentWeek = $(vLastWeekLastYr);

ELSE

LET vCurrentWeek = $(vCurrentWeekThisYr);

ENDIF



View solution in original post

4 Replies
Not applicable
Author

Script IF statements work differently than expression IF statments. Try this:

LET vLastWeekLastYr = 52;

LET vCurrentWeekThisYr = 53;

IF $(vCurrentWeekThisYr) > $(vLastWeekLastYr) THEN

LET vCurrentWeek = $(vLastWeekLastYr);

ELSE

LET vCurrentWeek = $(vCurrentWeekThisYr);

ENDIF



Not applicable
Author

This works too:

LET vLastWeekLastYr = 52;

LET vCurrentWeekThisYr = 53;

LET vCurrentWeek = If(vCurrentWeekThisYr > vLastWeekLastYr, $(vLastWeekLastYr), $(vCurrentWeekThisYr));



Not applicable
Author

Thank you Aaron! 🙂

Not applicable
Author

Hi

There are two different if-statements.
One that's used inside a load-statement (and that's the one you are using), and another one that's used as a control statement (this is the one you should be using). The syntax is as follows:

if $(vCurrentWeekThisYr) > $(vLastWeekLastYr) then
LET vCurrentWeek = $(vLastWeekLastYr)
else
LET vCurrentWeek = $(vCurrentWeekThisYr)
end if

Look in the QV help for more examples.

/Fredrik