What you might face is that the "order by" clause doesn't work when loading data from a qvd file.
But here your data is loaded directly from database and I'm not sure if it's the same case (will have to try it tomorrow at work).
As a solution, you can load your data first into a temp table without the "order by" clause, then do a resident load where you can order. It would go like this:
SQL SELECT *
Order By DATEMOV;
DROP Table tempSales;
LET varMinDate = ... //continue with your actual script
Hope this helps!
Thank you, this could be a solution, but it will result in a slower loading, so I am still trying to solve this working on the initialization:
LET varMinDate = Num(Peek('DATEMOV', 0, 'Sales'));
LET varMaxDate = Num(Peek('DATEMOV', -1, 'Sales'));
trying to find some other function to reach the same result