Results 1 to 4 of 4
  1. #1
    bruin4ever is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    2

    Update SQL with Averages

    Thank you, in advance for your help with this.

    I have a monthly currency table. I am looking to update the 5th column "YTD Avg" rate column with a running average based on Month End Rate. So Month 2 "YTD Avg" is avg for month 1&2, Month 3 YTD Avg is the avg for months 1,2,and 3, Month 4 YTD Avg is the average of months 1-4 and so on.

    I'm at a loss on how to write the update statement in Access 365. I created a duplicate table FX2. The standalone select statement below seems to work, but I can't convert it to the update statement

    SELECT FX2.Year, FX2.Month, FX2.Currency, avg([FX1 Rates].[Month End Rate])
    FROM FX2 INNER JOIN [FX1] ON (FX2.Currency = [FX1].Currency) AND (FX2.Year = [FX1].Year) AND (FX2.month >= [FX1].month)
    where FX2.YEAR =2020
    and FX2.CURRENCY= "AUD"
    GROUP BY FX2.Year, FX2.Month, FX2.Currency



    Year Month Currency Month End Rate YTD Avg
    2020 1 AUD 100 100
    2020 2 AUD 110 105
    2020 3 AUD 120 110
    2020 4 AUD 130 115
    2020 5 AUD 140 120
    2020 6 AUD 150 125

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    An UPDATE involving a non-editable query as data source won't work.

    Options:

    VBA looping recordsets and setting value of field

    or

    write records to temp table and use table as source for UPDATE

    or

    don't save calculated data, calculate it when needed.
    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
    bruin4ever is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    2
    Thank you very much! Appreciate your 3rd option.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You should pause and fix your field names. "YEAR", "MONTH" and "CURRENCY" are reserved words in Access and shouldn't be used for object names.
    Also remove the spaces in object names.

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

Similar Threads

  1. Averages with zero in calculation
    By Polarbilly in forum Queries
    Replies: 6
    Last Post: 03-23-2018, 02:16 PM
  2. Calculating Averages
    By chr1stoper1 in forum Access
    Replies: 1
    Last Post: 05-05-2017, 05:26 AM
  3. average of averages?
    By mejia.j88 in forum Reports
    Replies: 5
    Last Post: 01-24-2012, 08:09 AM
  4. averages in a report?
    By mejia.j88 in forum Reports
    Replies: 3
    Last Post: 01-18-2012, 06:12 PM
  5. Averages
    By Nixx1401 in forum Queries
    Replies: 1
    Last Post: 05-26-2011, 10:08 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