Count distinct dates per customer

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,896
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
  8. 2003 or older
Platform
  1. Windows
i have a simple database which i have pruned for this post
CustId, OrderDate
2, 01/01/22
1, 19/11/22
2, 19/11/22
1, 19/11/22

I am creating a query to report on as follows, to extract, CustID, Year(OrderDate), Quarter

SELECT CustID, Year(["OrderDate"]) AS YearOrder, Val(Format(["OrderDate"],"q")) AS Qtr
FROM CurrentData
WHERE (((Year(["OrderDate"]))=Year(Now())))
GROUP BY CustID, Year(["OrderDate"]), Val(Format(["OrderDate"],"q"))
ORDER BY Year(["OrderDate"]);

As one customer can make several orders on one date I would like to call this a visit and sum these up by quarter to give the number of unique visits per quarter
using the above data i would like to see, but i cant quite get the syntax right to make access happy

custid, year, qtr, visits
2, 2022, 1, 1
1, 2022, 4, 2
2, 2022, 4, 1
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
does this not work ?

SELECT CustID, Year(["OrderDate"]) AS YearOrder, Val(Format(["OrderDate"],"q")) AS Qtr, count(*) as visits
FROM CurrentData
WHERE (((Year(["OrderDate"]))=Year(Now())))
GROUP BY CustID, Year(["OrderDate"]), Val(Format(["OrderDate"],"q"))
ORDER BY Year(["OrderDate"]);
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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