Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
alerse
Contributor II
Contributor II

How to Set variable in Expression

Hi

In my foreground text expression in my text object I want to define a variable. I've tried to put it in the first line but then it picks it up as text... Looks like the expression must start with a =...

My expression:


=Maxstring(If([L1] = Var5_4 and [L2]=d,[L1])) & chr(13)
&Maxstring(If([L1] = Var5_4 and [L2]=d,[HoverText])) & '.'& chr(13) &'Actual: '
&Maxstring(If([L1] = Var5_4 and [L2]=d,[Actual])) & chr(13) &'Target: '
&Maxstring(If([L1] = Var5_4 and [L2]=d,[Target])) & chr(13) &'Exceed: '
&Maxstring(If([L1] = Var5_4 and [L2]=d,[Exceed])) & chr(13) &'Threshold: '
&Maxstring(If([L1] = Var5_4 and [L2]=d,[Threshold]))


I want it to be something like this:


set L1Variable = Var5_4
set L1Variable = d
=Maxstring(If([L1] = L1Variable and [L2]=L1Variable ,[L1])) & chr(13)
&Maxstring(If([L1] = L1Variable and [L2]=L1Variable ,[HoverText])) & '.'& chr(13) &'Actual: '
&Maxstring(If([L1] = L1Variable and [L2]=L1Variable ,[Actual])) & chr(13) &'Target: '
&Maxstring(If([L1] = L1Variable and [L2]=L1Variable ,[Target])) & chr(13) &'Exceed: '
&Maxstring(If([L1] = L1Variable and [L2]=L1Variable ,[Exceed])) & chr(13) &'Threshold: '
&Maxstring(If([L1] = L1Variable and [L2]=L1Variable ,[Threshold]))


This will save me a lot of time when duplicating the text object... Currently I need to copy the new variables in all 6 lines;) First prise will be to set the object ID as L1Variable but the defining of variables here will do for now.

Thanks!!

Eon

5 Replies
Anonymous
Not applicable

Hi Eon,

You can't define variables within the separate objects. Instead you need to define a variable in the document (can be created under Settings and Document Properties, Variables). This variable can then be references within the text object. Or any other object for that matter.

alerse
Contributor II
Contributor II
Author

Hi

Thanks for your reply!

This will not work for me... I still need to change the variables in 6 places everytime I copy the text object (and I need about 200 of them)!

alerse
Contributor II
Contributor II
Author

Is there maybe a way I can create a little vb function in Tools -> Edit module and just call it from the expression?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Eon wrote:Is there maybe a way I can create a little vb function in Tools -> Edit module and just call it from the expression?


No, but you can do something simliar. Put the expression in a variable ("myvar") and call it with parameters.

$(myexpr('Var5_4', 'd'))

See this similar thread for more detail: http://community.qlik.com/forums/p/18140/70920.aspx#70920

-Rob

Not applicable

Hi,

you can also create this:


LET L1Variable = 'Var5_4';
LET L2Variable = 'd';
=Maxstring(If([L1] = '$(L1Variable)' and [L2]='$(L2Variable)' ,[L1])) & chr(13)
&Maxstring(If([L1] = '$(L1Variable)' and [L2]='$(L2Variable)' ,[HoverText])) & '.'& chr(13) &'Actual: '
&Maxstring(If([L1] = '$(L1Variable)' and [L2]='$(L2Variable)' ,[Actual])) & chr(13) &'Target: '
&Maxstring(If([L1] = '$(L1Variable)' and [L2]='$(L2Variable)' ,[Target])) & chr(13) &'Exceed: '
&Maxstring(If([L1] = '$(L1Variable)' and [L2]='$(L2Variable)' ,[Exceed])) & chr(13) &'Threshold: '
&Maxstring(If([L1] = '$(L1Variable)' and [L2]='$(L2Variable)' ,[Threshold]))


This way you only have to change the values of L1Variable and L2Variable.

Greetings

Rey-man