Results 1 to 15 of 15
  1. #1
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52

    Average of Calculated Field in Report

    Hello all. Hope you are all doing well. I have a calculated field in my table and query. It is the number of days between to dates. Works fine. I can get the average at the bottom of my query, but I can't figure out how to get that average onto my report. Is there a way to do this?

    I fully expect to get chastised for using calculated fields.

    Thanks in advance for the help.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Bill,

    Did you review the Similar Threads at the bottom of this page?

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    You use the Totals button and the AVG option, surely?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    In report or group header, textbox calculation: =Avg(fieldname)
    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.

  5. #5
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Thanks orange. I tried to do a search before I posted.

  6. #6
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    I tried that, it doesn't work. Perhaps because the field is calculated? I have a [start] and [end], both dates. [Days] calculates the number of days between the two. That works.
    I can go the query and get the average of [Days] there, I can't figure out how to get that AVG on to the report.

  7. #7
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    I tried that, it doesn't work. Perhaps because the field is calculated? I have a [start] and [end], both dates. [Days] calculates the number of days between the two. That works.
    I can go the query and get the average of [Days] there, I can't figure out how to get that AVG on to the report.

  8. #8
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by orange View Post
    Bill,

    Did you review the Similar Threads at the bottom of this page?
    I saw the post by @pbaldy that seems very close. The link doesn't work. Error - Office.com - Microsoft Support

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I have no problem with textbox aggregate calculation with table calculated field.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  10. #10
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by June7 View Post
    I have no problem with textbox aggregate calculation with table calculated field.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    Thank you. I'll do some research on that if I still don't get it, I'll put up a practice DB for help next week.
    Y'all have a great weekend.

  11. #11
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by June7 View Post
    I have no problem with textbox aggregate calculation with table calculated field.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    Here is a mockup I made. I get the same error in my actual.
    Attached Files Attached Files

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Works in Report Header/Footer or Group Header/Footer (as advised to use in post #4), not Page Footer.

    If you want to aggregate each page, review https://answers.microsoft.com/en-us/...c-014c06374408

    I have this code behind report in my db:
    Code:
    Option Compare Database
    Option Explicit
    Public intPageCount As Integer
    Public intPageTotal As Integer
    
    
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
       ' increment intPageCount and intPageTotal for each record printed
        intPageCount = intPageCount + 1
        intPageTotal = intPageTotal + Nz(Me!Qty, 0)
    End Sub
    
    
    Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
        'set the textboxes in footer
        Me.tbxPageCount = intPageCount
        Me.tbxPageTotal = intPageTotal
        'reset our counters
        intPageCount = 0
        intPageTotal = 0
    End Sub
    Difference is I don't set RunningSum property on UNBOUND textboxes in Page Footer. Maybe I should but report is only 1 page and have not tested for multiple pages.
    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
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by June7 View Post
    Works in Report Header/Footer or Group Header/Footer (as advised to use in post #4), not Page Footer.

    If you want to aggregate each page, review https://answers.microsoft.com/en-us/...c-014c06374408

    I have this code behind report in my db:
    Code:
    Option Compare Database
    Option Explicit
    Public intPageCount As Integer
    Public intPageTotal As Integer
    
    
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
       ' increment intPageCount and intPageTotal for each record printed
        intPageCount = intPageCount + 1
        intPageTotal = intPageTotal + Nz(Me!Qty, 0)
    End Sub
    
    
    Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
        'set the textboxes in footer
        Me.tbxPageCount = intPageCount
        Me.tbxPageTotal = intPageTotal
        'reset our counters
        intPageCount = 0
        intPageTotal = 0
    End Sub
    Difference is I don't set RunningSum property on UNBOUND textboxes in Page Footer. Maybe I should but report is only 1 page and have not tested for multiple pages.
    Thank you. I will try your link tomorrow. Much appreciated.

  14. #14
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Well, I tried it and got zeros and the error. I guess I'm not smart enough to do this.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Here's what I did with your posted db.

    1. moved Text11 to Report Footer section

    2. created UNBOUND textboxes in Page Footer section: tbxPageTotal, tbxPageCount. tbxPageAvg

    3. expression in tbxPageAvg: =[tbxPageTotal]/[tbxPageCount]

    4. pasted my code into report code module and changed Me!Qty to Me!Days

    5. added enough records to table to generate multi-page report for testing

    6. open report to PrintPreview

    I also changed report RecordSource to tblDays because I saw no benefit to using query.
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Average of Calculated Fields
    By M_vyncci in forum Access
    Replies: 6
    Last Post: 06-25-2016, 04:30 AM
  2. Replies: 5
    Last Post: 01-04-2014, 02:29 PM
  3. Replies: 4
    Last Post: 09-02-2013, 03:00 PM
  4. Replies: 6
    Last Post: 10-17-2012, 03:01 PM
  5. Replies: 5
    Last Post: 10-11-2012, 06:46 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