Calculating differences every two rows
Calculating differences every two rows
(OP)
If possible, I'd like to calculate the differences between every two rows (bold rows to be added):
9/2022 1000
9/2021 900
Variance 100
10/2022 1000
10/2021 1200
Variance (200)
I'm guessing I would use lead/lag and some kind of loop, but if anyone has something similar I'd be very interested to see how you did it. TIA.
9/2022 1000
9/2021 900
Variance 100
10/2022 1000
10/2021 1200
Variance (200)
I'm guessing I would use lead/lag and some kind of loop, but if anyone has something similar I'd be very interested to see how you did it. TIA.
RE: Calculating differences every two rows
Borislav Borissov
VFP9 SP2, SQL Server
RE: Calculating differences every two rows
As far as how to make it all work, here's an idea from another discussion:
https://stackoverflow.com/questions/1605325/aggreg...
(Not trying to point elsewhere, just happened to be one I found on the topic).
Here's what I searched for to get to that end: sql server aggregation difference between 2 row. Use that or similar if you want to find other examples. I've used both methods discussed in that thread in the past, myself. I think they'll both work.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57