Need Help with AND query

KAZSTREBOR

New Member
Joined
Feb 18, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi there. I'm not sure if it is even possible to do what I want in access. I need to create a query that will count the number of records if two conditions are met. I have 2 columns "Date Order Placed" and "Date Order Received". I need to be able to report the amount of orders placed in each month and the amount of those orders received in each month. IE- Count of orders placed in Jan AND received in Jan, orders placed in Jan AND received in Feb, and so on. Everything I try gives me the count for one column or the other but not both. Any help is much appreciated.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If there were 30 orders place in January and 20 received in January and you want the stats for January only, you expect to see
Placed = 30, Received = 20?
Probably a UNION query would be simple enough and provide that.

EDIT - Actually, a Totals query is probably more suitable.
 
Last edited:
Upvote 0
Something along the lines of
SQL:
SELECT Count(Tbl1.OrderDate) AS CountOfOrderDate, Count(Tbl1.ReceivedDate) AS CountOfRecDate
FROM Tbl1;
using your table and field names of course.
 
Upvote 0
I ran a mockup with some sample data. It involves 1 table and 2 queries. Results are below.

Table SampOrders
SampOrders SampOrders

IDOrderDateReceivedDate
1​
21-Jan-21​
27-Jan-21​
2​
10-Jan-21​
23-Jan-21​
3​
15-Jan-21​
07-Feb-21​
4​
17-Jan-21​
04-Mar-21​
5​
03-Feb-21​
16-Feb-21​
6​
14-Feb-21​
31-Mar-21​
7​
15-Jan-21​
05-Apr-21​
8​
12-Feb-21​
18-May-21​
9​
06-Apr-21​
23-Apr-21​
10​
08-Feb-21​
12-Feb-21​
11​
09-Feb-21​
08-Apr-21​
12​
12-Jan-21​
23-Jan-21​
13​
07-Apr-21​
17-Apr-21​
14​
11-Feb-21​
06-May-21​
Query1 OrderedReceivedQ

SELECT MonthName(Month(orderdate)) AS Ordered
, MonthName(Month(receiveddate)) AS Received
, 1 AS Num, Month([OrderDate]) AS O
, Month([receiveddate]) AS R
FROM samporders
ORDER BY Month([OrderDate])
, Month([receiveddate]);

Query2 OrderedReceivedFinalCountsQ

SELECT OrderedReceivedQ.Ordered
, OrderedReceivedQ.Received
, Count(OrderedReceivedQ.Num) AS CountOfNum
FROM OrderedReceivedQ
GROUP BY OrderedReceivedQ.Ordered
, OrderedReceivedQ.Received
, OrderedReceivedQ.O
, OrderedReceivedQ.R
ORDER BY OrderedReceivedQ.O
, OrderedReceivedQ.R;

Tested Output:

OrderedReceivedFinalCountsQ OrderedReceivedFinalCountsQ

OrderedReceivedCountOfNum
JanuaryJanuary
3​
JanuaryFebruary
1​
JanuaryMarch
1​
JanuaryApril
1​
FebruaryFebruary
2​
FebruaryMarch
1​
FebruaryApril
1​
FebruaryMay
2​
AprilApril
2​
 
Upvote 0
Solution
I ran a mockup with some sample data. It involves 1 table and 2 queries. Results are below.

Table SampOrders
SampOrders SampOrders

IDOrderDateReceivedDate
1​
21-Jan-21​
27-Jan-21​
2​
10-Jan-21​
23-Jan-21​
3​
15-Jan-21​
07-Feb-21​
4​
17-Jan-21​
04-Mar-21​
5​
03-Feb-21​
16-Feb-21​
6​
14-Feb-21​
31-Mar-21​
7​
15-Jan-21​
05-Apr-21​
8​
12-Feb-21​
18-May-21​
9​
06-Apr-21​
23-Apr-21​
10​
08-Feb-21​
12-Feb-21​
11​
09-Feb-21​
08-Apr-21​
12​
12-Jan-21​
23-Jan-21​
13​
07-Apr-21​
17-Apr-21​
14​
11-Feb-21​
06-May-21​
Query1 OrderedReceivedQ

SELECT MonthName(Month(orderdate)) AS Ordered
, MonthName(Month(receiveddate)) AS Received
, 1 AS Num, Month([OrderDate]) AS O
, Month([receiveddate]) AS R
FROM samporders
ORDER BY Month([OrderDate])
, Month([receiveddate]);

Query2 OrderedReceivedFinalCountsQ

SELECT OrderedReceivedQ.Ordered
, OrderedReceivedQ.Received
, Count(OrderedReceivedQ.Num) AS CountOfNum
FROM OrderedReceivedQ
GROUP BY OrderedReceivedQ.Ordered
, OrderedReceivedQ.Received
, OrderedReceivedQ.O
, OrderedReceivedQ.R
ORDER BY OrderedReceivedQ.O
, OrderedReceivedQ.R;

Tested Output:

OrderedReceivedFinalCountsQ OrderedReceivedFinalCountsQ

OrderedReceivedCountOfNum
JanuaryJanuary
3​
JanuaryFebruary
1​
JanuaryMarch
1​
JanuaryApril
1​
FebruaryFebruary
2​
FebruaryMarch
1​
FebruaryApril
1​
FebruaryMay
2​
AprilApril
2​
This worked great, thank you!
 
Upvote 0
You are very welcome. Good luck with your project.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top