Solved

Group Access data by month

Posted on 2014-11-06
3
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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