Count distinct dates per customer

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,873
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

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