Search code examples
functionqlikviewdollar-sign

qlikview set expression with chr()-function


I am Setting some variables in the script of my qlikview application. Later on I try to reuse one of the previous variables but qlikview is giving me an error.

SET vCurrentMonth = "=CAL.MONTH";
SET vMonthCounter = "SUM({<MONTH = {'$(vCurrentMonth)'}>} Counter)";
I was trying to use the $-expansion as already known from the normal set expressions that are not in the Script. But then I did not receive any data.

After some Research I found that I must replace the $ with the chr()-function.
SET vMonthCounter = "SUM({<MONTH = {'" & chr(36)& "(vCurrentMonth)'}>} Counter)";
But this chr()-function is returning a string so I don't receive the sum of my Counter but the string of the set Expression ($03). What am I doing wrong? Can anybody explain how to use this function in the script?

Thanks in advance


Solution

  • It works fine for me even without using the chr() function. I've added = before the sum (i've used simple string for vCurrentMonth and remove the = there):

    SET vMonthCounter = "=SUM({<MONTH = {'$(vCurrentMonth)'}>} Counter)";

    and then using the variable in text box (like below) is giving me the correct result:

    = vMonthCounter

    If you still prefer the chr() approach then some changes in the vMonthCounter are needed to get the same result:

    let vMonthCounter1 = '=SUM({ <category = {' & chr(39) & chr(36) & '(vCurrentMonth)' & chr(39) & '} >} value)';

    • set is replaced with let. let evaluates the expression and will actually run and replace the chr() with the symbols (btw when using set you are not obligated to enclose the string in any quotes)

    • replaced the start and end quotes with single quote

    • the single quotes inside the set expressions are replaced with chr(39)