×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Calculating differences every two rows

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.

RE: Calculating differences every two rows

How do you know which row is first and which is second?

Borislav Borissov
VFP9 SP2, SQL Server

RE: Calculating differences every two rows

So I assume you're doing a comparison of month by month, year over year? So you want to see for January this year vs last year, Feb for this year vs last year, etc?

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close