To improve the communication, and the chance of obtaining an answer which is usable for you, I would suggest that you elaborate a little more on your use case. To be precise,
What does your dataset look like?
What fields does your dataset have, and what type do these fields have?
Provide a minimalistic example of some data that you might have in that dataset.
I.e. not too many rows, but still enough rows to capture the essence of your case.
And finally, for that very concrete dateset, explain what kind of output you are looking for? Do this by providing your own manually computed and formatted results. It will enable the community to support you better.
After receiving Kaare’s response, I re-checked my dataset and found and corrected the problem. The periodOverPeriodLastValue function now works as per Max’s response.
Thank you both for your assistance. Much appreciated.