Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Set variable in script in QlikSense

I am trying to set a variable in the script of a load.


Variable Name

vCurrentQuarterNum

Expression

max({1<[Fiscal - Flag Current Period]={'Y'}>}[Fiscal - Quarter #])

What would be the syntax for this?

Thanks!

1 Solution

Accepted Solutions
lcontezini
Partner - Creator
Partner - Creator

You can try this, for example. It's much easier to reuse the filter in other expressions.

SUB ExpandMacro(vVariableName)

LET vVariableName = Text(Replace(vVariableName, '@', '$'));

END SUB

SET vFilterFlag =

[Fiscal - Flag Current Period]={'Y'};

SET vCurrentQuarterNum =

max({1<$(vFilterFlag)>}[Fiscal - Quarter #]);


Call ExpandMacro(vCurrentQuarterNum);

View solution in original post

9 Replies
rittermd
Master
Master

Let vCurrentQuarterNum = 'your expression';

YoussefBelloum
Champion
Champion

Hi,

can you share your data structure ?

what is the values on the [fiscal -quarter] ?

YoussefBelloum
Champion
Champion

Hi,

OP want a solution in the script, which is equivalent to his expression.. and set analysis don't work in the script..

he will need to use Max() function in a group by Clause with a WHERE or peek() function

Anonymous
Not applicable
Author

This issue I am running into there is that the expression has a field that has single quotes in it and it is causing the syntax to fail

[Fiscal - Flag Current Period]={'Y'}

lcontezini
Partner - Creator
Partner - Creator

SUB ExpandMacro(vVariableName)

LET vVariableName = Text(Replace(vVariableName, '@', '$'));

END SUB

SET vCurrentQuarterNum =

max({1<[Fiscal - Flag Current Period]={'Y'}>}[Fiscal - Quarter #]);


Call ExpandMacro(vCurrentQuarterNum);

YoussefBelloum
Champion
Champion

you can purge your field in the script like this:

purgechar([Fiscal - Flag Current Period],chr(39))


and your expression will work

lcontezini
Partner - Creator
Partner - Creator

You can try this, for example. It's much easier to reuse the filter in other expressions.

SUB ExpandMacro(vVariableName)

LET vVariableName = Text(Replace(vVariableName, '@', '$'));

END SUB

SET vFilterFlag =

[Fiscal - Flag Current Period]={'Y'};

SET vCurrentQuarterNum =

max({1<$(vFilterFlag)>}[Fiscal - Quarter #]);


Call ExpandMacro(vCurrentQuarterNum);

Anonymous
Not applicable
Author

a number: 1-4

Anonymous
Not applicable
Author

This worked! Thanks so much!