Count then sum on another field

bigal.nz

Registered User.
Local time
Tomorrow, 12:23
Joined
Jul 10, 2016
Messages
92
I have data in MS Access like:
Code:
+------------+-----------+
| DateStart  | PATIssued | 
+------------+-----------+ 
| 12/12/2004 | Yes       | 
+------------+-----------+ 
| 13/12/2004 | No        | 
+------------+-----------+ 
| 14/12/2004 | No        | 
+------------+-----------+ 
| 12/12/2004 | No        | 
+------------+-----------+ 
| 12/12/2004 | Yes       | 
+------------+-----------+ 
| 14/12/2004 | No        | 
+------------+-----------+ 
| 13/12/2004 | Yes       |
I want to count number of records per day for the past week by day of week, and in another column count records where PATIssued = Yes
So the results would look like:

Code:
  Date       DayCount   PATCount 
Monday              3        2 
Tuesday             2        1 
Wednesday           2        0
I have gotten as far as

Code:
  SELECT Format(DateValue(DateStart),"dddd") AS DayOFWeek,  PATIssuedYN, Count(Table1.DateStart) 
AS DayCount, Sum(IIf([PATIssuedYN]="Yes",1,)) FROM Table1 WHERE (((Table1.DateStart) Between 
DateAdd("d",-7,Now()) And Now())) GROUP BY DateValue(DateStart), PATIssuedYN;

The problem is that this returns:


Code:
  Date       PATIssuedYN   DayCount PATCount 
Monday        No            1          
Monday        Yes           2        2 
Tuesday       No            1 
Tuesday       Yes           1        1 
Wednesday     No            2         
Wednesday     Yes           0        0
Where Monday is 12/12, Tuesday is 13/12 Wednesday is 14/12
 
Last edited:
Whats the difference between your desired results and your actual results? Hint: Why is PATIssuedYN in your actual results if you don't desire it to be?
 
Whats the difference between your desired results and your actual results? Hint: Why is PATIssuedYN in your actual results if you don't desire it to be?

Thanks - the working solution:
SELECT Format(DateValue(DateStart),"dddd") AS DayOFWeek,
Count(Table1.DateStart) AS DayCount, Sum(IIf([PATIssuedYN]="Yes",1,))
FROM Table1 WHERE (((Table1.DateStart) Between DateAdd("d",-7,Now()) And Now()))
GROUP BY DateValue(DateStart);
 

Users who are viewing this thread

Back
Top Bottom