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: 
Not applicable

If then else SYNTAX in scripts

I'm trying to something I think is simple; once again, the lack of useful documentation is tripping me up.

I have default dates set to load a document:

StartDate = MonthStart(today(),-1)

EndDate = MonthEnd(today(),-1)

These are fine for 90% of the time, but occasionally users want to run reports over different time periods. So, I tried this:

IF  $(vUserSetDates) THEN

Let StartDate = Input('Enter Start Date (MM/DD/YYYY)', 'Input required');

Let EndDate = Input('Enter End Date (MM/DD/YYYY)', 'Input required');

ELSE      

Let StartDate = MonthStart(Today(),-1);

Let EndDate = MonthEnd(Today(),-1);

END IF

where vUserSetDates is set to either "TRUE" or "FALSE" by a button on the sheet.

However, regardless of what vUserSetDates is, I get an error message, the input boxes ask me for start and end dates,

and then the dates are reset to the defaults anyway. In other words, all the commands execute and the "IF" structure is ignored.

According to the documentation, this is the correct way to structure an IF THEN ELSE statement. What am I missing?

Thanks in advance for your help.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Are you assigning string values like 'TRUE' and 'FALSE' to the variable?

Try using -1 and 0 instead, or

IF  '$(vUserSetDates)' = 'TRUE' THEN

...

View solution in original post

2 Replies
swuehl
MVP
MVP

Are you assigning string values like 'TRUE' and 'FALSE' to the variable?

Try using -1 and 0 instead, or

IF  '$(vUserSetDates)' = 'TRUE' THEN

...

Not applicable
Author

Thanks my friend, that did the trick.