Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    JonathanT is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    118

    Averaging calculated time fields

    I have a calculated time field on a report that holds a duration of time based on the start and end time of each record. I'm trying to average the durations for several records. For instance if my durations are 0:26, 0:25, and 1:03, this should average to 0:38. I'm stumped. I would like to do this on a report but I can also do this on a query if necessary

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    =Avg(DurationFieldName)

    in the report or group footer. Format the textbox as short time.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    How do you derive those values?

    You need to calculate decimal hour and use that to aggregate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    JonathanT is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    118
    I have a start time and and end time on each record. The difference between the two is my duration field. I use DateDiff("n",[starttime],[endtime])/60 to calculate the duration field to a decimal number field called [timediff] However when I try to either sum or average the [timediff] field in the header it's blank. Any ideas??

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI, that DateDiff() would need to be in the source query. You can't Sum, Avg, etc a calculated control on a form/report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    JonathanT is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    118
    I did and the result was wrong

  8. #8
    JonathanT is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    118
    I'll try to do the calculation the query. I've been trying to use the report header

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you still have trouble, something more than "the result was wrong" would help. Perhaps a sample db.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    The complete expression must be in the aggregate calc. In textbox in report header:

    =Avg(DateDiff("n",[starttime],[endtime])/60)

    The advantage of doing aggregate calc in textbox is it allows you to include raw data records in report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    JonathanT is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    118
    Placing the DateDiff calculation in the report header did produce a result but not the correct one. The Duration values I'm trying average are decimals of time, .43, .42, 1.05, 0, 0. The average including the zeros is .38. If the zeros are not included the average is .63. The result I'm getting is .22. The duration field is formatted as Standard and the filed I'm using to average is formatted as Short Time.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Why are you not using the duration calc in the Avg? What is the other field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    JonathanT is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    118
    I'm going to start over. I haven't clearly explained my issue.

    1. I have a start time and and end time in each record. I have a calculation in a parameter query that calculates the difference between the two and converts it to decimal time. The field is called Duration. The result in the Duration field is also dependent on another field called DateWindow that has either a positive value or zero. If the DateWindow value is zero the the value in the Duration field is zero. If DateWindow has a value other than zero the the result in Duration is the difference between the start and end time. I use an IIF statement with the DateDiff function calculate the value in Duration. The Duration field in the query query returns the correct amount in decimal format.

    2. Now I want to to average the values in the Duration field on a report. Using =Avg([Duration]) in the report header does not return the correct result. My values in Duration are .43, .42, 1.05, 0, 0. The average including the zeros is .38. If the zeros are not included the average is .63. The result I'm getting is .22. The Duration field is formatted as Standard and the filed I'm using to average is formatted as Short Time.

    3. How do I get the right average result in the header?

  14. #14
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Duration should not be formatted as time. Conceptually it is time, but it is actually just a number, a count of seconds or minutes, etc.
    If the datediff is giving you seconds and you want to display minutes for example, you'll have to calculate the minutes, seconds / 60.

    The date/time format is for a point in time, not a duration of time.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    I still don't understand what 'field' is formatted as ShortTime. Do you mean 'textbox'? I also don't understand how ShortTime would show .22. Shows 12:00 for me.

    Formatting duration won't work. Duration is a quantity (with hours as the unit of measure), not time. Showing the quantity as hh:nn:ss will require another calc to convert to a string. Fairly common topic.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-16-2018, 02:24 PM
  2. Replies: 1
    Last Post: 04-12-2017, 07:39 AM
  3. Averaging fields with missing data
    By mfred1 in forum Queries
    Replies: 2
    Last Post: 03-19-2015, 08:32 AM
  4. Replies: 2
    Last Post: 08-21-2014, 08:36 AM
  5. Replies: 12
    Last Post: 10-01-2013, 12:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums