Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
petter
Partner - Champion III
Partner - Champion III

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?

Anonymous
Not applicable
Author

I added a sample data to make it more clear

jonathandienst
Partner - Champion III
Partner - Champion III

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