Share via

Using the Avg() Function on specific dates in reports

Anonymous
2016-10-08T19:04:54+00:00

Hello,

I have a report that lists values by time of day, grouped by day

I want to AVG the values for morning, afternoon, and evening.

The records have a date and time stamp in them 

I have tried several different things but always get a syntax error.

here is an example of what I have tried:

Avg([Copy Of qryEvening].Reading between -1+#6:00:00 PM# And [ReadingDate]+#1:00:00 AM# Or Between [ReadingDate]+#6:00:00 PM# And +1+#1:00:00 AM#) 

hopefully, this gives insight as to what I am trying to accomplish.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

17 answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2016-10-08T22:01:44+00:00

    Did you use the Report wizard to create the report? Please still show us your SQL, And show us the Group/Sort pane

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-10-08T20:58:46+00:00

    It isn't the query, it is the report, trying to group TOD, then I get mismatch error message, the Query works fine

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-10-08T20:41:10+00:00

    Access uses error message "data type mismatch in criteria expression" when that is not the problem.

    Post the complete SQL of the query.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-10-08T20:26:04+00:00

    When I try to group on "TOD" i receive an error message "data type mismatch in criteria expression"

    Was this answer helpful?

    0 comments No comments
  5. ScottGem 68,830 Reputation points Volunteer Moderator
    2016-10-08T19:21:17+00:00

    Add a column to a query like:

    TOD: IIF(TimeValue(datefield) BETWEEN #06:00 AM# AND #12:00 PM#,"Morning",IIF(TimeValue(datefield) BETWEEN #12:01 PM# AND #5:00 PM#, "Afternoon","Evening"))

    Then group your report by TOD and add an AVG to the Grouping.

    Was this answer helpful?

    0 comments No comments