Qlik Community

Ask a Question

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
March 11, 2PM EST: Do More with Qlik - Getting Started wtih Qlik Sense SaaS - Redux. REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
mgranillo
Specialist
Specialist

Dynamic Variable Name

Is it possible to set a variable name to include the current year?

For example:

set vCurrentYear=year(today());

set v&$(vCurrentYear)&Parm1 = .05;

I want this to evaluate to v2016Parm1=.05.

Thanks,

Mike

1 Solution

Accepted Solutions
rwunderlich
MVP & Luminary
MVP & Luminary

You are right. I totally misread the question. I believe the solution would be:

Let vCurrentYear=year(today());

set v$(vCurrentYear)Parm1 = .05;

-Rob

View solution in original post

8 Replies
rwunderlich
MVP & Luminary
MVP & Luminary

LET vMyVar = 'v' & $(vCurrentYear)& 'Parm1 = .05';


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

alexdataiq
Partner
Partner

So wouldn't this create a vMyVar variable with 'v2016Parm1 = .05' as value instead of a v2016Parm1 variable with '.05' as value?

Or you just need to use $(vMyVar) in place of the whole variable in the desired expression?

Regards

rwunderlich
MVP & Luminary
MVP & Luminary

You are right. I totally misread the question. I believe the solution would be:

Let vCurrentYear=year(today());

set v$(vCurrentYear)Parm1 = .05;

-Rob

View solution in original post

mgranillo
Specialist
Specialist

Thanks Rob, 

The proper syntax was really getting me here and I couldn't find another post on this. 

I really appreciate it.

Mike

mgranillo
Specialist
Specialist

I have one additional question about this topic: Does my variable need to be script defined?  I tried defining it in the app and couldn't get it to evaluate correctly. 

Thanks,

Mike

rwunderlich
MVP & Luminary
MVP & Luminary

I don't think there is any way to use a dynamic variable name from the UI Variable Overview.

-Rob

mgranillo
Specialist
Specialist

Thanks for confirming

SimonDB
Contributor II
Contributor II

Really helped me get a timestamp variable for each tab in my script. Thank you Rob!

// MAIN TAB
LET vTAB = 0;


// EVERY TAB IN SCRIPT
LET vTAB = $(vTAB)+1;
LET vTimeTab_$(vTAB) = TIMESTAMP(NOW());