Thanks for your reply. I copied the script and it is working. It took me some time to understand your logic but now it's clear. I was assuming that I needed the Peek/Previous but probably the lack of the DATE function it was not working. Thanks for your creative solution with the MAX function.