Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
LET vName = 'Num(Sum({<Type ={''Actual''}, Quarter = {' & Chr(36) & '(=Min(Quarter))}>} Sales,''#,##0.0'')';
May be this?
LET vName = '=Num(Sum({<Type ={'A'}, Year = {$(=Max(Year))}>} Sales,'#,##0.0')';
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)&')';
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.
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.
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.
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?
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.
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.
LET vName = 'Num(Sum({<Type ={''Actual''}, Quarter = {' & Chr(36) & '(=Min(Quarter))}>} Sales,''#,##0.0'')';