Easy way to calculate average number of daily records (1 Viewer)

gojets1721

Registered User.
Local time
Yesterday, 22:04
Joined
Jun 11, 2019
Messages
430
I have a query of complaints YTD. On a report, I'm trying to code a field to show the average daily number of complaints? Any suggestions on how to code that? I'm having a brain fart on how to do that tbh
 

plog

Banishment Pending
Local time
Today, 00:04
Joined
May 11, 2011
Messages
11,663
Depends on if we are counting or summing to get total complaints:

=SUM([Complaints])/DatePart("y", Date())
 

gojets1721

Registered User.
Local time
Yesterday, 22:04
Joined
Jun 11, 2019
Messages
430
Depends on if we are counting or summing to get total complaints:

=SUM([Complaints])/DatePart("y", Date())
We would be counting
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:04
Joined
Feb 19, 2002
Messages
43,430
Count(*) / dCount("*", "qDistinctDays")
You need a query with the count of distinct days.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:04
Joined
May 7, 2009
Messages
19,246
create first a Query that will Count How Many Days you already has (YTD).

1. qryNumDays
SELECT COUNT("1") AS NumDays FROM (SELECT [DateField] FROM yourTable GROUP BY [DateField]);

2. qryAverageDailyComplaint:

SELECT DSum("ComplaintQtyField", "yourTable") / DLookup("NumDays", "qryNumDays") As AvgDailyComplaint;
 

gojets1721

Registered User.
Local time
Yesterday, 22:04
Joined
Jun 11, 2019
Messages
430
create first a Query that will Count How Many Days you already has (YTD).

1. qryNumDays
SELECT COUNT("1") AS NumDays FROM (SELECT [DateField] FROM yourTable GROUP BY [DateField]);

2. qryAverageDailyComplaint:

SELECT DSum("ComplaintQtyField", "yourTable") / DLookup("NumDays", "qryNumDays") As AvgDailyComplaint;
Gotcha. However, step one isn't working for me. I think it's because my date field also includes the time. It's formatted like: mm/dd/yyyy 00:00am/pm
 

MarkK

bit cruncher
Local time
Yesterday, 22:04
Joined
Mar 17, 2004
Messages
8,186
If there is one row for each complaint, then to count your complaints YTD you would do...
Code:
DCount("*", "ComplaintTable", "ComplaintDate >= DateSerial(Year(Date()), 1, 1)")
If you want an average per day over the entire YTD period, you would divide by...
Code:
DatePart("y", Date())
If you need to count distinct days for your average, then drop the time using the DateValue() function, and save this as query qDistinctDays....
Code:
SELECT DISTINCT DateValue(ComplaintDate) FROM ComplaintTable;
Then divide by...
Code:
DCount("*", "qDistinctDays")
hth
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:04
Joined
Feb 28, 2001
Messages
27,288
I think it's because my date field also includes the time.
Code:
SELECT COUNT("1") AS NumDays FROM (SELECT [DateField] FROM yourTable GROUP BY Date([DateField]));

Use the DATE() function to strip the time from the date field.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:04
Joined
May 7, 2009
Messages
19,246
Gotcha. However, step one isn't working for me.
you can use DateValue:

SELECT COUNT("1") AS NumDays FROM (SELECT DateValue([DateField]) As Expr1 FROM yourTable GROUP BY DateValue([DateField]));
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:04
Joined
Sep 12, 2006
Messages
15,689
You probably want the date range for the report to evaluate the total day count.
I don't think you would want to just count the number of days with problems. But you may want to remove weekends and BH days.

eg If you have problems this week on Mon, Wed. Thu is that 3 days or 5 days (with Tue and Fri). You will know.
So the days count might be enddate +1 - startdate
 

gojets1721

Registered User.
Local time
Yesterday, 22:04
Joined
Jun 11, 2019
Messages
430
You probably want the date range for the report to evaluate the total day count.
I don't think you would want to just count the number of days with problems. But you may want to remove weekends and BH days.

eg If you have problems this week on Mon, Wed. Thu is that 3 days or 5 days (with Tue and Fri). You will know.
So the days count might be enddate +1 - startdate
That is correct. The above solutions are only counting days where problems occur. I'm looking simply a total count of all days from January 1 to today.
 

MarkK

bit cruncher
Local time
Yesterday, 22:04
Joined
Mar 17, 2004
Messages
8,186
Read post #7 more closely.
 

Users who are viewing this thread

Top Bottom