Counting data for the past 30 days

Keith13

New Member
Joined
Oct 6, 2016
Messages
5
I am trying to count the past 30 days order count but when doing so I get multiples of the same item for each day it was ordered. Is there away to count the past 30 days without list each individual day that it was purchased below is the sql and result example

Code:
SELECT Combine_Orders_ORder_Delivery_Group.ITEM_ID, Count([Combine_Orders_ORder_Delivery_Group]![ITEM_ID]) AS Item_Occurance, Combine_Orders_ORder_Delivery_Group.ORDER_DATE
FROM Combine_Orders_ORder_Delivery_Group
GROUP BY Combine_Orders_ORder_Delivery_Group.ITEM_ID, Combine_Orders_ORder_Delivery_Group.ORDER_DATE
HAVING (((Combine_Orders_ORder_Delivery_Group.ORDER_DATE) Between Date() And DateAdd("m",-1,Date())));

EX

item idamount date
123411/10/2016
123111/11/2016
123711/12/2016
456111/10/2016
456411/11/2016
456311/12/2016
789911/10/2016
789811/11/2016
789411/12/2016

<tbody>
</tbody>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I assume access should work similar to regular SQL commands, so I would try this

Code:
SELECT Count([Combine_Orders_ORder_Delivery_Group]![ITEM_ID]) AS Item_Occurance FROM Combine_Orders_ORder_Delivery_Group
HAVING (((Combine_Orders_ORder_Delivery_Group.ORDER_DATE) Between Date() And DateAdd("m",-1,Date())));
 
Last edited:
Upvote 0
Is your screen print what you are getting now, or your desired result?
If it is what you are getting now, what is it that you want to see?
Can you post an example?
 
Upvote 0
The table above is is what I get now the desired result would be one row for each item id and the amount totaled
 
Upvote 0
Remove the date field from the SELECT, GROUP BY and HAVING clauses, and add it just to the WHERE clause instead.
Code:
SELECT Combine_Orders_ORder_Delivery_Group.ITEM_ID, Count([Combine_Orders_ORder_Delivery_Group]![ITEM_ID]) AS Item_Occurance
FROM Combine_Orders_ORder_Delivery_Group
WHERE Combine_Orders_ORder_Delivery_Group.ORDER_DATE Between Date() And DateAdd("m",-1,Date())
GROUP BY Combine_Orders_ORder_Delivery_Group.ITEM_ID;
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,938
Members
451,730
Latest member
BudgetGirl

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