Jump to content

Current and previous month


Everton1878

Recommended Posts

Does anyone know the SQL (or MySQL?) I can use to report on the current month and for the previous month?

I've been asked to do a graph that would show the rating on calls for the current month and previous month on the same graph

It would be something along the lines of

Quote

WHERE DATEPART(m, date_created) = DATEPART(m, DATEADD(m, -1, getdate()))
AND DATEPART(yyyy, date_created) = DATEPART(yyyy, DATEADD(m, -1, getdate()))

Thanks,

Pete

Link to comment
Share on other sites

Hi @Everton1878

There are various ways you could do this, but the method I usually would go for is:

Previous Month

WHERE
h_datelogged >= LAST_DAY(NOW() - INTERVAL 2 MONTH) + INTERVAL 1 DAY 
AND
h_datelogged < LAST_DAY(NOW() - INTERVAL 1 MONTH)


This Month

WHERE
h_datelogged >= LAST_DAY(NOW() - INTERVAL 1 MONTH) + INTERVAL 1 DAY 
AND
h_datelogged < LAST_DAY(NOW())

Let me know if you have any problems
Kind Regards

Bob

Link to comment
Share on other sites

Thanks @Bob Dickinson that will help me with a few other graphs as well :)

I finally had some time yesterday to look through what I currently produce using an export from a view and what we have set up in the Advanced Analytics

Think I managed to get to grips with a measure for a percentage yesterday as well

Hopefully I'll be posting soon about the ones I don't think we can do

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...