Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Dollar sign in set analysis

Hello,

let say i got a variable vYear = 2017. So no expression, just a value.

I can use this at layout level without $-sign because its no expression.

But i do need to use it in set analysis like this:

{<Year={$(vYear)}>}

and not

{<Year={vYear}>}

or

{<Year={'vYear'}>}

?

Gets me confused a little bit.

-Philipp

4 Replies
Anil_Babu_Samineni

What you want to trying here from layout Tab. are you going to Hide and show controls ??

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
vikasmahajan

PFA detailed

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
avinashelite

When using a variable for text replacement in the script or in an expression, the following syntax is used:

$( variablename )

$( variablename) expands to the value in variablename. If variablename does not exist the expansion will be the empty string.

For numeric variable expansions, the syntax $( variablename ) will generate a number using the regional decimal separator, i.e. for many countries a decimal comma. Such an expansion should not be used for numbers inside the script since these must use decimal point. Instead the expansion $(# variablename ) should be used. (Note the hash sign). It always yields a valid decimal-point representation of the numeric value of variablename, possibly with exponential notation (for very large/small numbers). If variablename does not exist or does not contain a numeric value, it will be expanded to 0 instead.

Example:

After execution of the following script:

SET DecimalSep=',';

LET X = 7/2;

$(X ) will expand to 3,5 while $(#X ) will expand to 3.5.

Examples:

set Mypath=C:\MyDocs\Files\

...

load * from $(MyPath)abc.csv;

set CurrentYear=1992;

...

select * from table1 where Year=$(CurrentYear);

Dollar-Sign Expansion with Parameters

Parameters can be used in variable expansions. The variable must then contain formal parameters, such as $1, $2, $3 etc. When expanding the variable, the parameters should be stated in a comma separated list.

Examples:

set MUL=’$1*$2’;

set X=$(MUL(3,7)); // returns '3*7' in X

let X=$(MUL(3,7)); // returns 21 in X

If the number of formal parameters exceeds the number of actual parameters only the formal parameters corresponding to actual parameters will be expanded. If the number of actual parameters exceeds the number of formal parameters the superfluous actual parameters will be ignored.

Examples:

set MUL=’$1*$2’;

set X=$(MUL); // returns '$1*$2' in X

set X=$(MUL(10)); // returns '10*$2' in X

let X=$(MUL(5,7,8)); // returns 35 in X

The parameter $0 returns the number of parameters actually passed by a call.

Example:

set MUL='$1*$2 $0 par';

set X=$(MUL(3,7)); // returns '3*7 2 par' in X

Dollar-Sign Expansion with an Expression

Expressions can be used in dollar-sign expansions. The content between the brackets must then start with an equal sign:

$( =expression )

The expression will be evaluated and the value will be used in the expansion.

Example:

$(=Year(Today())); // returns e.g. '2008'

$(=Only(Year)-1); // returns the year before the selected one

Dollar-Sign Expansion of File - Include Statement

File inclusions are made using dollar-sign expansions. The syntax is then:

$( include=filename )

The above text will be replaced by the content of the file specified after the equal sign. This feature is very useful when storing scripts or parts of scripts in text files.

Example:

$(include=C:\Documents\MyScript.qvs);

Miguel_Angel_Baeyens

Short answer is: because it is a variable you need to expand it and therefore use $() instead of just the variable name. Otherwise, the set will select the string "vYear" instead of the value of the variable.

A different use case is $(=Year(Today())) (note the equal) to evaluate an expression and use its result as part of the set analysis.