Tuesday, November 29, 2011

Let versus Set (Again)

SET vString = 1 + 1; // The string "1 + 1";
LET vEvalute = 1 + 1; // The value 2

You can get very fancy using variables in Qlikview. You can include arguments inside your variables, so that you can use them like user defined functions.

So, if you wanted to create a 'function' to multiply two numbers you could use a Set like this

SET DOSTUFF = '$1*$2';

The $1 and $2 act as arguments. (Think %1 for a DOS .BAT file)

If you use a SET, it will plug in the arguments and evaluate as a string. i.e.

SET A = $(DOSTUFF(2,2)); // returns '2*2' in A

Note: The dollar sign in front of the DOSTUFF 'function', this signifies Dollar-Sign Expansion, basically some sort of text replacement happens between the parenthesis before it is evaluated.

So, if we instead use a LET

LET A = $(DOSTUFF(2,2)); // returns 4 in A

1 comment:

Anonymous said...

Hi Michael,

Great Blog! Actually I was searching for a Senior-Consultant/Team-Lead for QlikView / BI for an international company in Germany.

You look like a cool match! If interested (or know somebody who is) please let me know:

detailed info:
(*) http://valbonne-consulting.com/current-searches/51-germany/258-munich-senior-consultant-technical-lead-bi-bigdata-m-f

The role is a permanent/full-time position and salary package is very competitive.

Wish you a fantastic weekend!

best from the south of France,
Joachim Bauernberger

+33637712014
joachim@valbonne-consulting.com