Results 1 to 5 of 5
  1. #1
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255

    Time Elapse Formula

    I have 2 dates that i need to make a formula with and have used datediff for the most part. now i have an issue if the time period crosses years. For example, i need my formula to give me partial $ information based on year.



    FROMDATE: 12/14/2012
    TODATE: 3/18/2013

    Expense: 64,870

    I need the expense related to 1/1/2013 to 3/18/2013 in one column and 12/14/2012 to 12/31/2012 in another.. i have done it before but cannot find the query and believe it was a very rustic formula consisting of quite a few IIF statements.

    any ideas on how to make this as simple as possible?

  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
    Maybe like:

    BETWEEN [FromDate] AND IIf(Year([FromDate])=Year([ToDate]), [ToDate], "12/31/" & Year([FromDate]))

    BETWEEN IIf(Year([FROMDate])=Year([ToDate]), [FromDate], "1/1/" & Year([ToDate])) AND [ToDate])
    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
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255
    yes but need the $ associated with the "YTD" expense. For 2013 the $ should be 13,507.18 ((64,870/12)*(((#3/18/2013#-#1/1/2013#)/365)*12)) which is the expense related to the time between 1/1/2013 and 3/18/2013; 3,021.34 for 12/14/2012-12/31/2012..

  4. #4
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255
    Quote Originally Posted by June7 View Post
    Maybe like:

    BETWEEN [FromDate] AND IIf(Year([FromDate])=Year([ToDate]), [ToDate], "12/31/" & Year([FromDate]))

    BETWEEN IIf(Year([FROMDate])=Year([ToDate]), [FromDate], "1/1/" & Year([ToDate])) AND [ToDate])
    Invalid Syntax on the first between statement? Entered a comma without preceding value or identifier...

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    In GROUP BY query, try:

    IIf([fieldname] BETWEEN [FromDate] AND IIf(Year([FromDate])=Year([ToDate]), [ToDate], "12/31/" & Year([FromDate])), [Amount], 0)

    Then set Total row for that constructed field to Sum.

    Alternative maybe expression in textbox in group footer section of report:
    =Sum(IIf([fieldname] BETWEEN [FromDate] AND IIf(Year([FromDate])=Year([ToDate]), [ToDate], "12/31/" & Year([FromDate])), [Amount], 0))
    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. Replies: 42
    Last Post: 03-01-2013, 06:58 AM
  2. Please help with formula
    By JeanZander in forum Database Design
    Replies: 2
    Last Post: 01-07-2013, 04:39 PM
  3. Formula
    By Ray67 in forum Queries
    Replies: 53
    Last Post: 08-09-2012, 01:56 AM
  4. Replies: 1
    Last Post: 02-28-2012, 09:16 PM
  5. Replies: 7
    Last Post: 08-04-2011, 07:49 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