Solved

Group Access data by month

Posted on 2014-11-06
3
154 Views
Last Modified: 2015-01-04
I need to pull a query that returns information about quotes issued on a system by month. Specifically I need to see how many quotes, per month a particular rep has issued. I don't want to see a list of all the quoted dates, rather a list of all the months of the year with a number, or a zero, next to each month showing how many quotes have been issued.

Any suggestions welcomed.
0
Comment
Question by:snooflehammer
3 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 40427384
try this

select Format([datefield], "yyyy-mmm"), count(Format([datefield], "yyyy-mmm"))
from tableName
group by  Format([datefield], "yyyy-mmm")
0
 
LVL 25

Accepted Solution

by:
chaau earned 250 total points
ID: 40427517
The query provided by Rey will do the trick, however, if you really want to see the months with zero orders you will need to use this query:
select Format(dateSerial(ym.y, ym.m, 1), "yyyy-mm") as yyyymm, Format(dateSerial(ym.y, ym.m, 1), "yyyy-mmm") as yyyymmm, count(t.yy) as cnt
FROM
(SELECT DISTINCT Year([dateField]) as y, months.m 
FROM yourtable, 
(Select top 1 1 as m from yourtable UNION 
Select top 1 2 as m from yourtable UNION 
Select top 1 3 as m from yourtable UNION 
Select top 1 4 as m from yourtable UNION 
Select top 1 5 as m from yourtable UNION 
Select top 1 6 as m from yourtable UNION 
Select top 1 7 as m from yourtable UNION 
Select top 1 8 as m from yourtable UNION 
Select top 1 9 as m from yourtable UNION 
Select top 1 10 as m from yourtable UNION 
Select top 1 11 as m from yourtable UNION 
Select top 1 12 as m from yourtable) as months) as ym
LEFT JOIN (SELECT year([dateField]) as yy, month([dateField]) as mm FROM yourtable) as t
ON t.yy = ym.y AND t.mm = ym.m
group by  Format(dateSerial(ym.y, ym.m, 1), "yyyy-mm"), Format(dateSerial(ym.y, ym.m, 1), "yyyy-mmm")
ORDER BY 1

Open in new window

Will return something similar to this: query result
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40427614
In report design:

Add Group On Expression: Year(theDate)
Add Group On Expression: Month(theDate)

In Month group header:
add a field: =Year(theDate) & " - " & Month(theDate)
add a field: =Count(theDate)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question