If you’re getting SQL Server error 10753 that reads “The function ‘LAST_VALUE’ must have an OVER clause”, it’s probably because you’re calling the LAST_VALUE() function without an OVER clause.
The LAST_VALUE() function requires an OVER clause (and that clause must have an ORDER BY clause).
To fix this issue, include an OVER clause when calling the LAST_VALUE() function.