Results 1 to 2 of 2
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    Rolling 12 Calculation Query Criteria help

    I have a query that calculates a 12 Month Rolling SUM.

    First, I create this query, called QrySub. Essentially, this query creates a filed to determine where the year start date is, giving the record date.

    SELECT ValueT.ValueID, ValueT.OE, ValueT.MetricID, ValueT.Month_Year, ValueT.Months, DateAdd("yyyy",-1,[Month_Year])+1 AS YearStartFROM ValueT;
    Then, from here, I create another Query to actually run the Rolling 12 Sums:

    SELECT QrySub.ValueID, QrySub.OE, QrySub.MetricID, DatePart("yyyy",[qrysub]![Month_Year]) AS YearSort, DatePart("m",[QrySub]![Month_Year]) AS MonthSort, MonthName(DatePart("m",[QrySub]![Month_Year])) AS MonthDesc, QrySub.Month_Year, QrySub.Months, Sum(IIf([ValueT]![Month_Year] Between [QrySub]![YearStart] And [QrySub]![Month_Year],[ValueT]![Values],0)) AS Rolling12Sum, Sum(IIf([ValueT]![Month_Year] Between [QrySub]![YearStart] And [QrySub]![Month_Year],1,0)) AS Rolling12CountFROM QrySub LEFT JOIN ValueT ON (QrySub.OE = ValueT.OE) AND (QrySub.MetricID = ValueT.MetricID)
    GROUP BY QrySub.ValueID, QrySub.OE, QrySub.MetricID, DatePart("yyyy",[qrysub]![Month_Year]), DatePart("m",[QrySub]![Month_Year]), MonthName(DatePart("m",[QrySub]![Month_Year])), QrySub.Month_Year, QrySub.Months;
    This calculates the Rolling 12 Sum just fine, but there's a catch to the result that I want to capture.

    Say my dataset looks like this (note that my query considers more fields than just what is shown):


    MetricID Month_Year Values
    A1 1/1/2014 3289239
    A1 2/1/2014 1324089
    A1 3/1/2014 5646545
    A1 4/1/2014 4584899
    A1 5/1/2014 4983409
    A1 6/1/2014 9089834
    A1 7/1/2014 3920480
    A1 8/1/2014 9032840
    A1 9/1/2014 2093480
    A1 10/1/2014 2342343
    A1 11/1/2014 3294898
    A1 12/1/2014 3425234
    A1 1/1/2015 2460958
    A1 2/1/2015 2463293
    A1 3/1/2015 2463428
    A1 4/1/2015 2406541
    A1 5/1/2015 2408239
    A1 6/1/2015
    A1 7/1/2015
    A1 8/1/2015


    A1 9/1/2015
    A1 10/1/2015
    A1 11/1/2015
    A1 12/1/2015

    Now, my Rolling-12 calculation will display this:


    MetricID Month_Year Rolling12Sum
    A1 1/1/2014 3289239
    A1 2/1/2014 4613328
    A1 3/1/2014 10259873
    A1 4/1/2014 14844772
    A1 5/1/2014 19828181
    A1 6/1/2014 28918015
    A1 7/1/2014 32838495
    A1 8/1/2014 41871335
    A1 9/1/2014 43964815
    A1 10/1/2014 46307158
    A1 11/1/2014 49602056
    A1 12/1/2014 53027290
    A1 1/1/2015 52199009
    A1 2/1/2015 53338213
    A1 3/1/2015 50155096
    A1 4/1/2015 47976738
    A1 5/1/2015 45401568
    A1 6/1/2015 36311734
    A1 7/1/2015 32391254
    A1 8/1/2015 23358414
    A1 9/1/2015 21264934
    A1 10/1/2015 18922591
    A1 11/1/2015 15627693
    A1 12/1/2015 12202459


    I do a count to determine if there are INDEED 12 months to roll on. Which is a step in the right direction as you can see from the 2nd query with the field Rolling12Count. HOWEVER,

    Note that in the first table I listed that there are values up until 5/1/2015. I want the Query to ONLY SHOW Rolling12Sum's IF and ONLY IF there are indeed 12 months to roll on (which I capture), but that those 12 months also have values attached to them!

    Any help is greatly appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Not seeing a field Rolling12Count.

    The only year that will not have 12 months is the current year? Maybe just filter data to all records prior to Jan 1 of the current year? Or apply filter on the Rolling12Count to only show records that have 12? Or do a conditional calc in textbox on report: =IIf([Rolling12Count]=12, [Rolling12Sum], Null)
    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. Rolling-12 Month Sum/Average Calculation
    By McArthurGDM in forum Queries
    Replies: 8
    Last Post: 04-20-2015, 11:39 AM
  2. Rolling 3 month and 12 month Calculation
    By REGeekker in forum Programming
    Replies: 10
    Last Post: 03-30-2015, 07:29 PM
  3. Replies: 3
    Last Post: 06-26-2014, 03:02 PM
  4. Replies: 2
    Last Post: 04-29-2014, 03:04 AM
  5. Rolling 12 or 6 Month Query
    By Shakenaw in forum Access
    Replies: 2
    Last Post: 09-22-2011, 09:24 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