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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
nihhalmca
Specialist II
Specialist II

Loading Variables - Script line error

Hi All,

I am trying to load variables from excel spread sheet by for loop however, getting script line error while loading.

Variable looks like vName = Num(Sum({<Type ={'A'}, Year = {$(=Max(Year))}>} Sales,'#,##0.0').

I think, getting error due to single quotations.

Could you please assist on this.


Thanks,

Nihhal.

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

LET vName = 'Num(Sum({<Type ={''Actual''}, Quarter = {' & Chr(36) & '(=Min(Quarter))}>} Sales,''#,##0.0'')';

View solution in original post

11 Replies
Anil_Babu_Samineni

May be this?

LET vName = '=Num(Sum({<Type ={'A'}, Year = {$(=Max(Year))}>} Sales,'#,##0.0')';

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
avkeep01
Partner - Specialist
Partner - Specialist

First option to try, replace quotes and dollar signs with CHR(39) en CHR(36) (respectively ' and $).


SET vName = 'Num(Sum({<Type ={'&CHR39 &'A'&CHR(39)&'}, Year = {'&CHR(36)'&(=Max(Year))}>} Sales,'&CHR(39)&'#,##0.0'&CHR(39)&')';



Miguel_Angel_Baeyens

To "escape" the single quote sign, use another one in front, so in your expression:

LET vName = 'Num(Sum({<Type ={''A''}, Year = {$(=Max(Year))}>} Sales,''#,##0.0'')';

But using LET evaluates the expression on the right of the "=" before assigning the value to the variable, and since it is valid syntax, the part $(=Max(Year)) will be evaluated. It does not have any value during the script, so the result in the variable overview after the load will be

Num(Sum({<Type ={'A'}, Year = {}>} Sales,'#,##0.0')


I would use SET instead of LET and use Chr() function as mentioned above by A.M.

nihhalmca
Specialist II
Specialist II
Author

Hi Miguel,

I am loading 130 variables and changing quotes by chr(39) is time consuming so i tried to add one more quote front and tried to add front and back as well but no luck.

Miguel_Angel_Baeyens

I can only suggest you to use some text editor with Find and Replace and copy back to the script.

It likely didn't work because of the reason mentioned above, the set analysis, actually any expression in the form $() or $(=) will be evaluated prior to be assigned. During the script, most of these values are non existing, so the $() is expanded into null or garbage.

nihhalmca
Specialist II
Specialist II
Author

Hi Miguel,

No worries about nulls because i will store those into variables. I am thinking about your first suggestion ""escape the single quote sign, use another one in front", is it possible?

Miguel_Angel_Baeyens

Yes it is, use the example I wrote above. But the issue with the expressions will persist: as soon as the script finds a $() or $(=) the contents between the brackets will be evaluated and the expression will not be kept.

nihhalmca
Specialist II
Specialist II
Author

Hi A.M - I tried and did not work, think i am doing mistake somewhere else.

I am coping my actual variables here, could you edit it please.

1. VariableName = vName

1. VariableValue = num(sum({<Type={'Actual'}, Quarter={$(=min(Quarter,1))}>} Sales,'#,##0.0;(#,##0.0)')

2. VariableName = vLabel

2. VariableValue = Only({<Quarter={$(=min(Quarter,1))}>} QuartrandYear) &chr(13)&'(A)'

Thanks,

Nihhal.

Miguel_Angel_Baeyens

LET vName = 'Num(Sum({<Type ={''Actual''}, Quarter = {' & Chr(36) & '(=Min(Quarter))}>} Sales,''#,##0.0'')';