Using variables to replace numbers

The same way you can use variables to replace string values in set modifiers, you can use variables to hold numbers if the field is of a number type. An example of a field of number type is Year

The following example returns the sales for the year 2018:

sum({$< [Year] = {2018} >} Sales)

The Year field is of a type number, and thus the values in the set analysis must not be enclosed in single or double quotes. 

Assuming we create two variables in the script, one for the year and one for my field Sales as follows:

LET vCurrentYear = year(today());
SET vMySalesField = '[Sales]';

We could now make the expression use the two variables as follows:

sum({$< [Year] = {$(vCurrentYear)} >} $(vMySalesField))

Note that vCurrentYear will return 2018 which will be selected in the field [Year] which is of a number type. The aggregation sum() will be performed on the field [Sales]. vMySalesField contains a string, but because we omit the single or double quotes, Qlik Sense will consider it a field and not a string. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.207.113