Results 1 to 14 of 14
  1. #1
    Deeb1234 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2023
    Posts
    6

    Calculate Ave/Max/Min of Group Subtotals

    Hi:

    I created an Access 365 report that displays job-to-date cost information. It is grouped by ProjectName, and it successfully subtotals the sub category records within each project in the ProjectName footer. My ultimate goal in the report header would be to display the average, maximum, and minimum $ values of each group as shown in the picture.

    What I've tried so far is to create a text box for each value in the report header. For example, to calculate the average of all the subtotals, I've tried =Avg(Sum([JTDCost])) as the Control Source formula, but I get "Cannot have aggregate function in expression Avg(Sum([JTDCost])))." Is it even possible to do what I'm attempting? Thanks for any insights or other options I should try.



    Click image for larger version. 

Name:	Report Example.jpg 
Views:	36 
Size:	218.2 KB 
ID:	50375

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Conceptually, isn't avg(JTDCost) same as avg(sum(JTDCost)) ?

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    All I can think of is hidden textboxes in the report footer that hold the calculations and refer to those in the header.

    Hard to produce header totals when no data has been produced, as the header is written first.
    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
    Deeb1234 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2023
    Posts
    6
    Avg(JTDCost) will calculate an average of all the 5 records ($255,094), but it is the average of the totals ($345,395, $247,154, $682,921) that I'm looking for ($425,157) .

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    Are you able to upload a copy of the Database?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  6. #6
    Deeb1234 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2023
    Posts
    6
    Unfortunately, the database contains a lot of proprietary information.

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    Ok Then all you need is in the ProjectName Footer add an Unbound Control to Count(ProjectName) and name it txtCount

    Then in the Report Footer add an Unbound Control and Sum([NameofTotal in ProjectName Footer])/[txtCount]
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #8
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Sounds like you're after the avg, min, max of the results of a subquery. There's many different ways to approach this.

    This first step might be to just create aggregate query like so:
    Click image for larger version. 

Name:	1.png 
Views:	20 
Size:	28.7 KB 
ID:	50391

    Step two: Then use the DAvg(), DMin(), DMax() functions in your report header textbox's control source. The domain parameter for these functions would be the name of your query.

    I assume the report is based on a filtered set of projects. Your query from step one can reference your report or a form or whatever and apply a where clause, or you can pass a filter to the domain functions from step 2.

    (EDIT)
    See attached for example database
    Attached Files Attached Files

  9. #9
    Deeb1234 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2023
    Posts
    6
    Mike, thanks for your reply. At your suggestion, I did add an unbound text box control to the ProjectName footer with a Control Source of =Count([ProjectName]) and named it txtCount. The name of my Total in the ProjectName footer is MyJTDCost. In the report footer, I also added an unbound text box control with a control source of =Sum([MyJTDCost])/[txtCount]. When I view the report, however, I get prompted to enter a parameter value for MyJTDCost. Thoughts?

  10. #10
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    When you get asked for a Parameter it normally means a spelling mistake. Check the name of the Total Control in the ProjectName Footer.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Deeb1234 View Post
    Unfortunately, the database contains a lot of proprietary information.
    We do not need all the db, just enough to see the problem.
    To hide the proprietary information, review this post https://www.accessforums.net/showthread.php?t=82910&page=2&highlight=randomize# 19

    Make sure it is on a copy of your DB. Comapct and zip, and upload.
    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

  12. #12
    Deeb1234 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2023
    Posts
    6
    Hi, kd2017:

    I think the example database you put together is on the right track of what I'm trying to do. I'll take a closer look to see if I can make that work with mine. Thanks so much for your time and effort!

  13. #13
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    I added a Form to record all costs for a Project
    Then using kd2017's example I added a Report to show all required values.
    Attached Files Attached Files
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  14. #14
    Deeb1234 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2023
    Posts
    6
    I cannot thank everyone enough for all the input I've received on this post. Between the suggestions and example databases contributed, I now have a way forward to accomplish what I set out to do. Now it's just a matter of finding time to work on implementing those ideas. THANKS EVERYONE!

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

Similar Threads

  1. Replies: 4
    Last Post: 11-10-2015, 01:11 PM
  2. Subtotals in Reports
    By School Boy Error in forum Reports
    Replies: 3
    Last Post: 10-24-2013, 12:07 PM
  3. Query Subtotals???
    By claysea in forum Queries
    Replies: 3
    Last Post: 02-20-2012, 11:29 AM
  4. More detailed subtotals
    By kcmiuser in forum Queries
    Replies: 0
    Last Post: 06-27-2011, 06:10 AM
  5. Replies: 0
    Last Post: 08-07-2008, 07:02 PM

Tags for this Thread

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