Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
zakpullen
Creator
Creator

Expression works in table, but not as a variable

Hi,

This expression works perfectly well in a chart/table:

Max({<Year={'$(=Max(Year))'}>}Score)

It doesn't work as a variable.

set vTEST = Max({<Year={'$(=Max(Year))'}>}Score) 

 

Thanks

 

Labels (3)
8 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @zakpullen ,

 

A few thoughts for your consideration:

- What's the purpose of using single quotes in the Set Analysis filter? If the Year field is numeric, then quotes are not needed. The reason for this question is that quotes are usually causing trouble when storing formulas in variables.

- When you say "doesn't work in a variable", what do you mean? What are you expecting to see as the value of the variable, and how are you using the variable in your measures?

The way it's presented, the variable should store the formula (not the result), and it should be used in a measure like this:

$(vTest) 

What exactly doesn't work? Can you share more details, screen shots, or a sample app?

Cheers,

Oleg Troyansky

P.S. 

Allow me to invite you to my Qlik Expert Class that I'll be teaching in Vienna, Austria on September 22-24. I will be teaching advanced data modeling, advanced scripting, performance optimization, and advanced aggregation and Set Analysis techniques. You will learn the most advanced Qlik methodologies that will help you solve tough problems like this one.

 

anat
Master
Master

you can try using $(vTEST)

zakpullen
Creator
Creator
Author

I've tried variations of the variable. The quotes were one variation, it doesn't work without them either.

The variable doesn't return a result when put into a straight table or chart. It returns a '-'.

 

Ta

zakpullen
Creator
Creator
Author

That's what doesn't work.

Kaushik2020
Creator III
Creator III

Is the Year being passed when you edit the expression ? 

kaushi2020_0-1754384984850.png

 

zakpullen
Creator
Creator
Author

This works (returns the correct year when used in a table)

set yr = Max(TrustYr);

marcus_sommer

UI expressions should rather not be defined within script-variables because the possible need of quotes and/or other variables and/or any $-sign expansion makes a valid syntax usually far more complex as there were any benefits.

An alternatively might be to define these expressions externally within a data-base or Excel and then reading this data within a loop and assigning the content per peek() to the variable (prevents any evaluation of the content at this time). You should have a lot of such expression-variables and good reasons for them to add this kind of complexity to your applications.  

rafaelencinas
Partner - Creator II
Partner - Creator II

Hi @zakpullen !

I get what you want, but it's not the right way..

Let me know if I can help you

This: Max({<Year={'$(=Max(Year))'}>}Score)

1 - It will work in charts because charts "evaluate" the sentence as formula

 

2 - set vTEST = Max({<Year={'$(=Max(Year))'}>}Score) 

- It wil store "as text" your variable ( remmember to do it with single quotes.;

- if you want to use this expression in charts , use $(vTEST) , instead of the formula]

- If you want to do it, store text to use as formula, try Master Items instead of variables

 

3 - If you want to get the max score during script execution you need:

Temp:

Max(Year) as max_year

From yourqvd;

let vMaxYear = peek('max_year',0,'Temp');

Drop table Temp;

 

TempMaxScore

Load Max(Score) as MaxScore

from yourqvd

Where year = $(vMaxYear);

let vMaxScore = peek('MaxScore',0,'TempMaxScore');

 

Bye!

 

 

 

Senior Qlik Architect
Cobra, Stallone, "You're a problem and I'm the solution"