Results 1 to 6 of 6
  1. #1
    nagiese is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Nashville, TN
    Posts
    43

    Question Need a formula to Calculate Date Ranges

    Currently I have a series of parameter queries that require the user to input the beginning and ending date range to calculate the 4,6,9,12 & Left-to-Go month forecasts, it is cumbersome and it leaves lots of room for human error to leave these queries as human input required. Does anyone know a formula that I could use instead? It would have to refer to the Fiscal year and period that is input into the beginning form as the starting point then it would have to eventually calculate the ranges in yyyypp format. I would need a formula that would calculate the range for 4 month period, 6 month period, 9 month period, 12 month period, & Left- to - Go period (= current period+1 till end of year). An example of my current query is below.

    Code:
    INSERT INTO [mtb-9mnth Dmd Fcst] ( [Import Year], [Import Period], [New League], [New Group], Style, [Color Code], [SumOfResultant Forecast], [AvgOfStandard Cost] )
    SELECT [Demand fcst].[Import Year], [Demand fcst].[Import Period], [Demand fcst].[New League], [Demand fcst].[New Group], [Demand fcst].Style, [Demand fcst].[Color Code], Sum([Demand fcst].[Resultant Forecast]) AS [SumOfResultant Forecast], Avg([Demand fcst].[Standard Cost]) AS [AvgOfStandard Cost]
    FROM [Demand fcst]
    WHERE ((([Demand fcst].[Forecast Year Period]) Between [Enter Beginning YearPd for 9 mnth:] And [Enter Ending YearPd for 9 mnth:]))
    GROUP BY [Demand fcst].[Import Year], [Demand fcst].[Import Period], [Demand fcst].[New League], [Demand fcst].[New Group], [Demand fcst].Style, [Demand fcst].[Color Code]
    HAVING ((([Demand fcst].[Import Year])=[Forms]![frm-Year_Pd]![Year]) AND (([Demand fcst].[Import Period])=[Forms]![frm-Year_Pd]![Period]) AND (([Demand fcst].[New League]) Not In ("BLANKS","HARLEY")));



    If these queries would be better written as VBA I'm not apposed to doing that, I just didn't know how to go about doing that.

    Any help would be greatly appreciated
    Thanks in advance Nena

  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
    Yes, can do that. Can't completely eliminate user input but can structure query and form to minimize invalid criteria input.

    But why are you saving aggregate data to table?
    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
    nagiese is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Nashville, TN
    Posts
    43
    Quote Originally Posted by June7 View Post
    Yes, can do that. Can't completely eliminate user input but can structure query and form to minimize invalid criteria input.

    But why are you saving aggregate data to table?
    I have to save the data to a table becuase it it exported out to an Excel file and then pivot reports are created from the data. How do I calculate the month ranges based on the input for the current period and year that is currently inputted into the form by the user?

  4. #4
    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 sure you 'have' to save to table. Queries can be exported to Excel.

    Not quite sure what you are asking for. If you want the parameters to reference controls on form where user inputs criteria, something like:

    WHERE ((([Demand fcst].[Forecast Year Period]) Between [Forms]![formname]![beginningcontrolname] And [Forms]![formname]![endingcontrolname])))
    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
    nagiese is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Nashville, TN
    Posts
    43
    These are a series of append queries, that utilize the same two tables to extract and calculate what excess inventory would be at certain period ranges, i.e. one append query appends the 4 month range, one appends the 6 month range, etc... I have to use separate append queries and append the data to one table because I'm using the data to compare against the various ranges (ex. Item xyz had inventory excess of 100 units at 4 months, by 6 months it has 90 units, at 12 months it still has 90 units; this tells me that there are no foretasted sales for Item xyz past 4 months, which indicates an inventory issue.) Currently each of my append queries ask the user to input the period range (ex. if your current period is 4 your next 120 day(4 month) period range would be 5 and 8). I'm looking for a function(formula) that would configure the period range based on what the current period input is on a form. Dose a formula like that exist if so How would I write that in an access query criteria field?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    A start date can be input then use DateAdd function to calculate end date. The Interval, Number, Date arguments can all be provided by reference to inputs on a form.
    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. How to Program Two Date Ranges?
    By Jaynen in forum Database Design
    Replies: 5
    Last Post: 02-22-2013, 06:58 AM
  2. How to Compare Two Date Ranges?
    By Jaynen in forum Access
    Replies: 1
    Last Post: 02-19-2013, 05:26 PM
  3. Searching for Date Ranges
    By phd42122 in forum Access
    Replies: 2
    Last Post: 05-07-2012, 07:20 AM
  4. Query for gaps in date ranges
    By kagoodwin13 in forum Queries
    Replies: 6
    Last Post: 03-19-2012, 07:00 PM
  5. Working with date ranges
    By Acegundam in forum Queries
    Replies: 3
    Last Post: 11-04-2011, 02:04 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