Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
zagzebski
Contributor

Creating a variable for expression (not working)

I am trying to create variables for all my commonly used expressions. This is just one example below:

Let vFSRevMaxYear = 'Sum({$<[GL Dashboard]={'Revenue'},[Entity Location]={'01-WC,'03-EC'},Calendar_Year={$(=Max(Calendar_Year))}>} [Amount GL])*-1';

This expression doesn't work as I keep getting a "script line error"  - is it because of dashes or apostrophes? If so what is the best solution?

Thanks in advance,

Steve

6 Replies
MVP
MVP

Re: Creating a variable for expression (not working)

I think some help here

Escape sequences

try

Let vFSRevMaxYear = 'Sum({$<[GL Dashboard]={''Revenue''},[Entity Location]={''01-WC'',''03-EC''},Calendar_Year={$(=Max(Calendar_Year))}>} [Amount GL])*-1';

Not applicable

Re: Creating a variable for expression (not working)

Hi,

I suggest you to use chr(39) function whenever you to a single quote in a string or chr(34) for double quotes, escaping it will work too, but sometimes it gets messy.

Ryuma Nakano.

zagzebski
Contributor

Re: Creating a variable for expression (not working)

It didn't give me an error when I did what you recommended,  but the variable returns a "0" instead of the correct amount.

Steve

mov
Esteemed Contributor III

Re: Creating a variable for expression (not working)

Something like that, if I didn't miss anything:

Let vFSRevMaxYear = 'Sum({$<[GL Dashboard]={' &chr(39)&  'Revenue'  &chr(39) & '},[Entity Location]={'  &chr(39) & '01-WC'  &chr(39) & ','  &chr(39) & '03-EC'  &chr(39) & '},Calendar_Year={$(=Max(Calendar_Year))}>} [Amount GL])*-1';

Edit:  a way to test is to put this into a text box and see if it builds what you need:

= 'Sum({$<[GL Dashboard]={' &chr(39)&  'Revenue'  &chr(39) & '},[Entity Location]={'  &chr(39) & '01-WC'  &chr(39) & ','  &chr(39) & '03-EC'  &chr(39) & '},Calendar_Year={$(=Max(Calendar_Year))}>} [Amount GL])*-1'

zagzebski
Contributor

Re: Creating a variable for expression (not working)

Dang. It runs, but just gives me a "0". If I have the same expression in a text box it gives me a value.

Steve

mov
Esteemed Contributor III

Re: Creating a variable for expression (not working)

I hope you run it on the front end, not in the script.

Anyway, it's one thing to build this variable but another is to test the expression itself.  You have to upload your app for that sort of help.  Syntax looks fine to me.

Community Browser