Expression for finding the timestamps of most recent purchases, counting backwards


Apologies if this already answered elsewhere but I couldn’t find it anywhere.

I am trying to find the interval between the last 2 purchases each customer has made.

I am able to find the earliest timestamps by counting up and can find the very last purchase by using ‘last’, but have been unable to find a way to ‘count backwards’ and find the second to last purchase etc.

Does anyone have any idea how this would be possible?

Thanks in advance :slight_smile:

I assume you store a datetime when purchase / transaction was completed? If so, you can use date sorting and limit (2) to get last added entries…

Relevant documentation:


Thanks for this. Unfortunately it all seems a bit beyond me lol.

Does this have to be done within the APIs specified in the documentation or are you aware of a way to do this within the expressions in Bloomreach?

I can speak to our IT team if this is the only way to action this as it will probably make more sense to them.