Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Setting a variable in script...

Hi All,

I want to set a varible from code that results in a YTD-like value (in the attached example). I am able to create an expression in a table to get the result. I can also set the variable in the variablescreen and use that to display the desired value, but because of reasons of reusability and the number of variables I need, I want to set the variable in code. This results in an error.

I have tried a lot, but possibly not everything. Maybe some of you guys might be able to come up with a suitable solution.

Kind regards, vBeijnen

1 Solution

Accepted Solutions
marcus_sommer

It is a difficult matter ... cause are special characters. In most cases it is enough to replace single quotes with double quotes, but here it seems it is the $ sign - see here http://community.qlik.com/message/337484#337484 and also the attachment.

set vFromScript = 'Count({1<Date={"<=#(=max(Date))"}>} Label)';
let vFromScript = replace('$(vFromScript)', '#', chr(36));

- Marcus

View solution in original post

4 Replies
marcus_sommer

It is a difficult matter ... cause are special characters. In most cases it is enough to replace single quotes with double quotes, but here it seems it is the $ sign - see here http://community.qlik.com/message/337484#337484 and also the attachment.

set vFromScript = 'Count({1<Date={"<=#(=max(Date))"}>} Label)';
let vFromScript = replace('$(vFromScript)', '#', chr(36));

- Marcus

Not applicable
Author

Hi vBeijnein

it is beacause of the $ sign in the string

you have to split up your string like

SET v = first_part_string & chr(36) & second_part_string  : chr(36) for $ sign

Idem ifyou use simple/double cotes

best regards

chris

Not applicable
Author

Thank you kindly, Marcus!

Not applicable
Author

Thanks, Christianj, Marcus beat you to it... this time.