Solved

Group Access data by month

Posted on 2014-11-06
3
143 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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 24

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now