Monthly Statistics

  • Thread starter Thread starter Gary B
  • Start date Start date
G

Gary B

Regarding the following query, how can I show ClaimCount
for each month.

A Row for each month. But over a two year period, there would be 24 rows
returned, not a steady 12.


SELECT DateValue(Claims.ClaimsDate) AS ClaimDate, Count(Claims.ClaimsKey) AS
ClaimCount
FROM Claims
GROUP BY DateValue(Claims.ClaimsDate)
 
SELECT Month(DateValue(Claims.ClaimsDate)) AS ClaimMth,
Count(Claims.ClaimsKey) AS
ClaimCount
FROM Claims
WHERE ClaimsDate > DateAdd("yyyy",-1, Date())
GROUP BY Month(DateValue(Claims.ClaimsDate))
 
Are you saying you want 24 rows, or you don't want them?

Duane's shown you how to only get the last 12 months.

To get 24 rows, you could use:

SELECT Format(Claims.ClaimsDate, "yyyy-mm") AS ClaimMth,
Count(Claims.ClaimsKey) AS ClaimCount
FROM Claims
GROUP BY Format(Claims.ClaimsDate, "yyyy-mm")

or (to be sure it's only 24 months worth)

SELECT Format(Claims.ClaimsDate, "yyyy-mm") AS ClaimMth,
Count(Claims.ClaimsKey) AS ClaimCount
FROM Claims
WHERE ClaimsDate > DateAdd("yyyy",-2, Date())
GROUP BY Format(Claims.ClaimsDate, "yyyy-mm")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Selecting data 2
top 5 days for each user 12
Count of in Range of Dates 17
counting both the month and the past 12 months 3
Query problem 3
Format Date to 1st day of month 1
Date Formatting 5
Rolling 3 Month Average 1

Back
Top