Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Dynamic Variable in QVS/Load Script

Hi

I am trying to calculate a bunch of variables that dynamically calculate some KPIs based on a slider. The slider changes the variable "vActualMonth".

When I define the variable manually, it works just perfectly fine. When I try to define that variable in the load script or in a QVS, the variable within the variable is replaced with the value and it no longer works dynamically.

Here is what I would need:

SET vKPI_AATotalCost = '=Sum({$<RMonth={"<=$(vActualMonth)"}, RType={"Actual"}, AcctCode=>} If(AcctCode >= 6000 AND AcctCode <= 6999, InvAmount))';

When I define this in the load script, the variable is defined as:

=Sum({$<RMonth={"<=6"}, RType={"Actual"}, AcctCode=>} If(AcctCode >= 6000 AND AcctCode <= 6999, InvAmount))

So the $(vActualMonth) is replaced with its value 6. How can I prevent this to happen?

I know I could define the variables manually, but because it's quite a bunch of them, it would be much more efficient, to have that done in the script...

Thanks for any input.

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

LET vActualMonth= 5;

LET vKPI_AATotalCost = '=Sum({$<RMonth={"<=$' & '(vActualMonth)"}, RType={"Actual"}, AcctCode=>} If(AcctCode >= 6000 AND AcctCode <= 6999, InvAmount))';

Hope this helps you.

Regards,

Jagan.

View solution in original post

4 Replies
tresesco
MVP
MVP

One way is to use replace() to use '$' indirectly. Check: Re: Variable interpreted in script

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

LET vActualMonth= 5;

LET vKPI_AATotalCost = '=Sum({$<RMonth={"<=$' & '(vActualMonth)"}, RType={"Actual"}, AcctCode=>} If(AcctCode >= 6000 AND AcctCode <= 6999, InvAmount))';

Hope this helps you.

Regards,

Jagan.

jagan
Luminary Alumni
Luminary Alumni

Better expression using only set analysis

LET vActualMonth= 5;

LET vKPI_AATotalCost = '=Sum({$<RMonth={"<=$' & '(vActualMonth)"}, RType={"Actual"}, AcctCode={">=$(6000)<=$(6999)"}>}InvAmount)';

Regards,

Jagan.

Not applicable
Author

Excellent. That was what I was looking for. Thanks a million...