It has become interesting to try to solve your task. I propose to solve the task using the data island, transferring all the calculations to the script. In the attached file QVF, as an variant, an implementation example. All comments are in script code.
I will be glad if I could help you.
Temp_5Sec.qvf 192.0 K
In this case your ID keeps going up together with the date. When you select a date/month, you can use MAX(ID) to find out what your highest ID is or better said, your starting point. At this point you can add the 4 ID's previous to this point and add them to your MAX(ID) and you will have the 5 highest ID's.
Hope this works.