Count distinct dates per customer

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,895
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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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