You can get a prior day value using the Lag Function in SQL Server.
In this video I show you how to create a prior day squeeze of profit using the Windowing Lag function in TSQL.
This video builds on the prior day’s video, Moving Average with Windowing.
Video: Prior Day Profit using the Lag Function in SQL Server
How to use the SQL Lag Function for Prior Day Squeeze.
I use the Wide World Importers and the following scripts:
select [Invoice Date Key], Profit, Lag(Profit,1) OVER (ORDER BY [Invoice Date Key]) as PriorDayProfit, Profit - isnull(Lag(Profit,1) OVER (ORDER BY [Invoice Date Key]),0) as DailySqueeze from dbo.ProfitByDate order by 1
Link to the Microsoft SQL Server Over Clause.
See the original SQL Prior Day Profit – Lag Windowing Function video.
[…] video builds on the prior day’s video, Prior Day Profit using the Lag Function with Windowing […]