Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

danielco223
New Contributor III

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
Contributor

Re: Set variable in script in QlikSense

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);

9 Replies
rittermd
Honored Contributor

Re: Set variable in script in QlikSense

Let vCurrentQuarterNum = 'your expression';

YoussefBelloum
Esteemed Contributor

Re: Set variable in script in QlikSense

Hi,

can you share your data structure ?

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

YoussefBelloum
Esteemed Contributor

Re: Set variable in script in QlikSense

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

danielco223
New Contributor III

Re: Set variable in script in QlikSense

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
Contributor

Re: Set variable in script in QlikSense

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
Esteemed Contributor

Re: Set variable in script in QlikSense

you can purge your field in the script like this:

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


and your expression will work

lcontezini
Contributor

Re: Set variable in script in QlikSense

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);

danielco223
New Contributor III

Re: Set variable in script in QlikSense

a number: 1-4

danielco223
New Contributor III

Re: Set variable in script in QlikSense

This worked! Thanks so much!

Community Browser