Skip to main content

New to Qlik Sense

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

Qlik Cloud Maintenance is scheduled between March 27-30. Visit Qlik Cloud Status page for more details.
Showing results for 
Search instead for 
Did you mean: 
Creator III
Creator III

When to use $(variable) and when just to use variable?

I'm a bit confused on when to use $(variable) and when just to use variable.  I have the following script;

For vYear = 2010 to 2015

For vMonth = 1 to 12

vMonth = vYear & NUM(vMonth,'00')

<Do stuff>

WHERE {[0CALMONTH].[$(vmonth))]};

But should that bolded line be vMonth = $(vYear) & NUM ($(vMonth),'00')?

As far as I can tell they do the same thing (in this instance).

I understand that $(variable) is saying "don't interpret this as a literal string" but that doesn't always matter, so is it just a matter of "best practice" to always use $(variable) or is there actually different functionality?


3 Replies
MVP & Luminary
MVP & Luminary

Luminary Alumni
Luminary Alumni


In script SQL/LOAD you should always use the $() to embed the variable value.

In the front end if you are giving = in the variable definition then you can directly use variable name, otherwise you have to give $(variablename) to evaluate the expression.

Hope this helps you.



Partner - Champion III
Partner - Champion III

This expression is OK as a let expression. No need for the expansion here.

Let vMonth = vYear & NUM(vMonth,'00');

Expansions are necessary in SQL expressions because the database server has no concept of QV variables. Expansions are also necessary in set expressions and sometimes when you need to inject some dynamic text into a statement.

In the front end, if the variable is defined with a leading =, then it is globally evaluated and it can be used without an expansion (it already contains the result of the expression). If not, then you need to inject the variable into the expression using a $ expansion. For example:

     Set vMaxDate = '=Date(Max(Date))';

     Use in expression:  =vMaxDate

     Set vMinDate = 'Date(Min(Date))';

     Use in expression    ='$(vMinDate)'  // quotes needed for a date

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