JeffreyLazo
JeffreyLazo

Reputation: 853

YTD Query comparing this year to last year

I am trying to provide a percentage of growth from Last YTD to Current YTD

I have my current YTD query

select sum(total) from invoiceinfo
WHERE InvoiceDateTime BETWEEN DATEADD(yy, DATEDIFF(yy,0,GETDATE()), 0) AND GETDATE()

How do I query for last YTD for the same day as this year. I imagine once I have this query I will then need to calculate the percentage of growth

Upvotes: 0

Views: 7535

Answers (1)

eugenioy
eugenioy

Reputation: 12403

For the Last YTD I believe you can use this query below.

You need to basically replace your GETDATE() with the same day of last year: DATEADD(yy, -1, GETDATE()).

select sum(total) from invoiceinfo
WHERE InvoiceDateTime 
BETWEEN DATEADD(yy, DATEDIFF(yy,0,DATEADD(yy, -1, GETDATE())), 0) 
AND DATEADD(yy, -1, GETDATE())

Upvotes: 1

Related Questions