Can you try to use the rank function instead? For my use cases, I’ve found that it works better than first value or last value.
Take a look at this: