Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

cagataym
New Contributor III

Nested variable in script

LOAD * Inline [

PRODUCT, YEAR, values

A, 2017, 10

B, 2017, 15

A, 2016, 5

B, 2016, 8

];

Set vMaxYear = max(YEAR);

Let vSum = Replace( 'sum({<YEAR ={@($(vMaxYear))} >} values)', '@', Chr(36));

In my expression, $(vSum)  outouts 0.

I've tried the following but non-seem to work using Qlik Sense.

Set vMaxYear = max(YEAR);

Let vSum = Replace( 'sum({<YEAR ={@($(vMaxYear))} >} values)', '@', Chr(36));

Let vSum2 = Replace( 'sum({<YEAR ={@($(=vMaxYear))} >} values)', '@', Chr(36));

Let vSum3 = Replace( 'sum({<YEAR ={@"($(=vMaxYear))"} >} values)', '@', Chr(36));

Let vSum4 = Replace( 'sum({<YEAR ={@(=vMaxYear)} >} values)', '@', Chr(36));

3 Replies
MVP
MVP

Re: Nested variable in script

The first two lines work as it is supposed to work.

What do you mean when you say "I cannot make this work". What do you want to happen?

Highlighted
cagataym
New Contributor III

Re: Nested variable in script

I added a sample data to make it more clear

MVP
MVP

Re: Nested variable in script

I do the same thing like this

Set vMaxYear = max(YEAR);

Set vSum = Sum({<YEAR = {#(=vMaxYear)}>} values);

Let vSum = Replace(vSum, '#', '$');

The advantage by separating the replace() is that I can clearly see what the expression result will be.

I would normally test this by entering these expressions in temporary text boxes to be sure that everything is working as expected

=Sum({<YEAR = {2018}>} values)

=max(YEAR)

=$(vMaxYear)

=vSum

=$(vSum)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein