Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
felcar2013
Partner - Creator III
Partner - Creator III

Variable defined in script not working

hi, i want to get this variable to work in my Expression, but it is not working

i defined in the script the variable like this

SET vL.CustomerTimestampPrevMonth=chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39);

and after running the script, i see in the Variable Overview under Settings that the variable is shown as:

chr(39)&date(addmonths(date#(GetFieldSelections(KUNDE_ZEITSTEMPEL),'YYYY/MM'),-1),'YYYY/MM')&chr(39) , which is not working in my Expression.

It works when i manually add the " = " sign infront of it in the variable overview. However i cannot get to create the complete variable expression in the script.

I also created this in the script,

SET vL.CustomerTimestampPrevMonth='=chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39)';

but in the varibale overview appears as:

'=chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39)'

and it is also not working. Any idea why not?  (i tried with chr(61) too, same result)

thanks

1 Solution

Accepted Solutions
swuehl
MVP
MVP

If you just want to add the equal sign:

SET vL.CustomerTimestampPrevMonth= =chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39);

View solution in original post

9 Replies
sunny_talwar

Have you tried using LET?

LET vL.CustomerTimestampPrevMonth=chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39);

Mark_Little
Luminary
Luminary

Hi,

How you using in the expression?

You Tried

$()

$(=)

Mark

felcar2013
Partner - Creator III
Partner - Creator III
Author

yes, did not work

felcar2013
Partner - Creator III
Partner - Creator III
Author

yes, it did not work

marcus_sommer

I use quite often double-quotes around variable-definitions like:

SET vL.CustomerTimestampPrevMonth="=chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39)";

Also the suggestion from Mark to use $-sign expansion is often helpful: The Magic of Dollar Expansions

However much easier are pure numeric values to handle. In this case maybe with a additionally field MonthCounter - Re: Howto make a variable to calculate quarters regarding year changes? - which is associated to [customer_timestamp] and then to use:

set var = "max(MonthCounter)-1";

which avoids the whole formatting-stuff.

- Marcus

Mark_Little
Luminary
Luminary

HAve you just tried

Set vL.CustomerTimestampPrevMonth = date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')

As you seem to be adding the actual ' symbol in?

Or maybe purgechar(vL.CustomerTimestampPrevMonth,'chr(39)') in a text box and see if that is the right result?

Mark

felcar2013
Partner - Creator III
Partner - Creator III
Author

thanks, i am trying this

swuehl
MVP
MVP

If you just want to add the equal sign:

SET vL.CustomerTimestampPrevMonth= =chr(39)&date(addmonths(date#(GetFieldSelections(customer_timestamp),'YYYY/MM'),-1),'YYYY/MM')&chr(39);

felcar2013
Partner - Creator III
Partner - Creator III
Author

it is right like this, thks