Announcements
cancel
Showing results for
Did you mean:
Creator

## defining variable in script

i want to include a set analysis expression in script:

variable name:

condition1

definition:

year1={\$(=Year(Max(date1))-1)},month1={\$(=Month(Max(date1)))}

// where year1,month1 and date1 are attributes from my data source

expression:

Sum({<\$(condition1)>}amount1)

this can be easily done by storing it through "Settings">"Variable Overview"

but how can i manage the variable condition1 in "edit script"?

it is quite confusing to me for when to apply dollar sign, using let or set, ... etc

i have read blogs from Henric, but i still don't understand how to do it

http://community.qlik.com/blogs/qlikviewdesignblog/2013/11/04/the-magic-of-variables

http://community.qlik.com/blogs/qlikviewdesignblog/2013/11/18/dollar-expansions

thank you

1 Solution

Accepted Solutions
Anonymous
Not applicable

Set analysis doesn't work in script unfortunately. you'll have to develop a specific script that performs the logic of your set analysis.

EDIT:
SET command fixes the content of your variable.

i.e. SET x = 1+2

When interpreted by using dollar sign expansion \$(x) will give 1 +2

LET x = 1+ 2

When interpreted \$(x) will give 3

Hope this helps

6 Replies
Anonymous
Not applicable

Set analysis doesn't work in script unfortunately. you'll have to develop a specific script that performs the logic of your set analysis.

EDIT:
SET command fixes the content of your variable.

i.e. SET x = 1+2

When interpreted by using dollar sign expansion \$(x) will give 1 +2

LET x = 1+ 2

When interpreted \$(x) will give 3

Hope this helps

Specialist

Why do you want to do this in your script?

Your expression can be calculated in the front end. It will be dynamic too, displaying the current selection as well.

If your goal is to always calculate for the max date you can add to your set analysis the following statements:

Sum({<\$(=Year(Max(date1))-1)},month1={\$(=Month(Max(date1))), year = , mont =, >}amount1)

The year = and month = statements eliminate the selections done on these dimensions in list boxes.

Creator

Hello Jerry,

Hope are doing well.

1. SET: is used in the script to store value (text/numeric) in a variable
2. LET: is used in the script to store a value having some Qlikview function in a variable

e.g.

• Just type below two commands in your script editor

SET vName1=Upper(Jerry);

LET vName2= Upper(Jerry);

• Check the values stored under these two variables
• Even while defining them in the script, you can see the difference in color, Suggestion starts appearing

3.  Dollar sign expansion (DSE): is used to resolve/ refer a variable which contains numeric value or uses Qlikview functions. It can not be used to resolve a variable which contains text value e.g. vName1 in above case. DSE is not desired if the variable contains some plain number, but its a good practice to use DSE.

DSE should not be used to resolve variable which contains Text value, else it will output a null/ missing value.

Creator
Author

but i get the solution from an older post: Putting Dollar Expansion in Variable

either

1) using Replace() function (but that does not work for me, i don't know why)

2) split the string after any dollar sign and concatenate segments manually

Contributor

hi,

would you please explain me this.

Let  x=left(y,2)

"y" is one of my column in a table.

how can i replace y to other columns,

for instance if

= x (Z),

the the answer be the same as = left(Z,2),

Best regards

Contributor III

look for variable with parameters

but here is the short version

define x as:

Left(\$1,2)

Then you may call it like:

\$(x(Z))

and that will expand to

Left(Z, 2)

Juan Manuel Lopez Felizzola
Community Browser