Results 1 to 4 of 4
  1. #1
    PogoP is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2018
    Posts
    1

    Offsetting an Average

    I'm relatively new to Access. I have a table with data against each month.
    What I'm trying to do is work out an average of February through to July and apply this in October then an average of August through to January which would be applied in April.
    Can anyone suggest the best way of doing this in Access?

    01-Feb-18 450
    01-Mar-18 425
    01-Apr-18 476
    01-May-18 450
    01-Jun-18 479
    01-Jul-18 520
    01-Aug-18 523
    01-Sep-18 435
    01-Oct-18 475 466.67 Average
    01-Nov-18 500
    01-Dec-18 280
    01-Jan-19 349
    01-Feb-19
    01-Mar-19
    01-Apr-19 427.00 Average


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Won't be easy. Possibly involve DAvg() and/or VBA custom function.
    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.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    If your table doesn't have a primary key field, you'll be making this more difficult, I think. Should you go the vba function route, the sql below might help with the calculation, but you'd have to figure out a way to input the date ranges. That could be a table of start and end dates, form values, array (less attractive I think) or other input. The sql as written could get you 2 values; Max of date and the average, then you'd have to find the record with that EXACT date (if you're using time, that might be a problem) and update the average.

    However, it is advisable to NOT store calculations in a table, so this ought to be calculated on a form or report only.

    Note - these are not formatted for vba but should be OK in sql design view. Dte is date/time field in table tblAvgData.
    Code:
    SELECT TOP 1 DMax("[Dte]","tblAvgData","[Dte] >=#02/01/2018# And [Dte]<= #07/01/2018#") 
    AS MaxDte, DAvg("[amount]","tblAvgData","[Dte] >=#02/01/2018# And [Dte]<= #07/01/2018#") 
    AS AvgAmt FROM tblAvgData;
    If you do have an primary key ID field, then the update is safer in that the sql can return the ID of the record related to the calculation.
    Code:
    SELECT TOP 1 DMax("[ID]","tblAvgData","[Dte] >=#02/01/2018# and [Dte]<= #07/01/2018#") AS 
    MaxID, DMax("[Dte]","tblAvgData","[Dte] >=#02/01/2018# and [Dte]<= #07/01/2018#") AS 
    MaxDte, DAvg("[amount]","tblAvgData","[Dte] >=#02/01/2018# and [Dte]<= #07/01/2018#") AS AvgAmt
    FROM tblAvgData;
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Peter M is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2017
    Posts
    67
    What is the overall goal you are trying to achieve? Is this an average that needs to be calculated repeatedly (and offset?) I.e. Next month will you need March-August and Sep-Feb?
    If not and the averages are static (it will always be Feb-July and Aug-Jan) then you might consider adding a field called AvgGroup and populating it with Group1 for Feb-July and Group2 for Aug-Jan. Then you can just take the average where AvgGroup = Group1.

    Also, when you say "Apply to October," what do you mean? Do you want to make a calculation with the result?

    (Have you considered making a query that calculates the average where Date is Between #1-Feb-2018# and #31-Jul-2018#?)


    Click image for larger version. 

Name:	Qry_Avg.jpg 
Views:	6 
Size:	133.4 KB 
ID:	35618

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

Similar Threads

  1. Average on a Group Average
    By Lykins in forum Reports
    Replies: 2
    Last Post: 04-24-2017, 01:28 PM
  2. Replies: 2
    Last Post: 04-29-2014, 03:04 AM
  3. Average of an average
    By audbene in forum Reports
    Replies: 1
    Last Post: 12-19-2012, 02:28 PM
  4. Average help please
    By C90RanMan in forum Programming
    Replies: 1
    Last Post: 08-01-2010, 12:14 PM
  5. Replies: 13
    Last Post: 05-28-2010, 11:57 AM

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