2

Is there any reason that this syntax shouldn't work in Qlikview load script??

Let v_myNumber = year(today());
Let v_myString = '2017-08';

If left($(v_myString),4) = text($(v_myNumber)) Then
    'do something
Else
    'do something else
End If;

I've tried both ways where I convert variable string to number and evaluate against the number variable directly and this way. They won't evaluate to equivalence when they should..

Scott
  • 107
  • 1
  • 1
  • 15
  • 1
    You don't need to do the dollar sign expansion with your `let` variables. Try: `left(v_myString,4) = text(v_myNumber) Then...` – bdiamante Sep 19 '17 at 17:59
  • Ok...I was wondering about that. Can you quickly explain when dollar sign expansion is needed and when not? Thank you! – Scott Sep 19 '17 at 20:05

2 Answers2

3

Left function is expecting a string as is getting something else as a parameter. As you are currently doing, the function will be called as Left(2017-08, 4) which is unhandle by QlikView.

If you use Left('$(v_myString)',4), it will evaluate as Left('2017-08', 4) as work as expected. Just adding quotes around the variable it should work.

Although QlikView calls them variables, they should really be seen as "stuff to replaced (at sometimes evaluated) at runtime", which is slightly different from a standard "variable" behaviour.

BrunoMarques
  • 557
  • 2
  • 11
  • This makes it make sense to me. Basically it came down to the fact that it wasn't evaluating it as a string - unless I either remove the dollar expansion or put single quotes around it. Thank you – Scott Sep 20 '17 at 20:36
3

Dollar sign expansion is a big subject, but in short:

  • if you are setting a variable - no need for $().
  • if you are using a variable - you can use $(). depends on its context.
  • if you are using a variable that needs to be evaluated - you have to use $(). for example in a load script: let var1 = 'if(a=1,1,2)' - here later on the script you will probably want to use this variable as $(var1) so it will be evaluated on the fly...

I hope its a little more clear now. variable can be used in many ways at even can take parameters!

for example:

var2 = $1*$2

and then you can use like this: $(var2(2,3)) which will yield 6

For further exploration of this, I would suggest reading this

EldadT
  • 912
  • 7
  • 21
  • Thank you for the explanation. I didn't realize you could create variables like that which essentially act as functions. pretty neat. – Scott Sep 20 '17 at 20:38