when you use
set before a variable it would put the text into the variable
so in your case the variable would be
if you put let before the variable it would calculate the formula and put the value to tha varaible
so in your case
let vExercicioRef=MakeDate(2011,2,1) ;
the result will be
vExercicioRef = 01/02/2012
very useful information, my previous experience had teach me that floor or int are very useful for removing the time part of datetime values. It's like an universal solution , independent of technology.
But, it seems to me that the answer for my question is: when we use calculated expressions, LET is better. SET works more like a constant/literal expression declaration.
So is my understanding.
What is happening in your expression not using Floor() -and sounds kind of buggy to me-, is that LET evaluates first the right part, then stores, so the logic steps that QlikView does according to your example are
LET vExercicioRef = MakeDate(2011, 2 ,1); // your sentence // QlikView does MakeDate(2011, 2, 1) = 01/02/2011 01 / 02 / 2011 = 0,000248632 // So Date($(vExercicioRef)) = Date(0.000248632) = 30/12/1899
And that is because you are evaluating twice. The first when using LET (creates the date), the second when using $() (dividing the day into the value of month into the value of year). If you use instead
The result will be as expected.
Hope that sheds some light.
Thanks for sharing. I was only showing how QlikView deals with dates. I always use the no-quotes no-dollar-expansion when the variable has been assigned with LET, and I don't need to evaluate twice the results. It makes more sense to me and makes the code cleaner. By the way, I always try to use Date#(something, 'format') instead of MakeDate() whenever possible, but that's another story
SET is, exactly as you say, a literal declaration rather than an evaluation.
SET v1 = 1+1;
-> v1 will have the value 1+1
LET v1 = 1+1;
-> v1 will have the value 2.
I will almost exclusively use LET with variables. Unless I need to create a macro function:
For dates, I always use Floor because it means that I don't need to worry about the single quotes when using it and I don't need to try and re-convert it again. E.g.:
Where DateField > $(vDateStart)