Results 1 to 7 of 7
  1. #1
    Ellen07886 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    2

    Complex date calculations


    Hello

    Newbie here looking for help.

    I have a database which I need to add a calculated field in, I currently do this in Excel and copy the data across but there are lots of records and I'd like to streamline the process if I can, so I want to add a calculated field which will provide me with a deletion date based on the following criteria:

    deletion date =
    DateofReport + 22 years if Age is blank or
    DateofReport + 4 if Age >=18 or
    DateofReport + number of years between Age and 18 eg Age is 6 so the number of years between 6 and 18 is 12.

    This is the formula used in Excel =IF(Age=" ",DateofReport,IF(Age>=18,DateofReport+4*365,Dateo fReport+(22-Age)*365))

    Is it possible to do this in Access? I really don't know where to start.

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Research DateAdd Function for Access. you can add or subtract years, days, months, etc. to calculations. And yes you can create same type of formulas in Access.

    https://www.techonthenet.com/access/...te/dateadd.php

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    I need to add a calculated field in
    Hopefully you don't mean in a table, nor do you intend to store the calculation. Things like this can be done with nested IIF statements or you can use a function and set the name of the function to be the form control's control source property or as a calculated query field. The thing about DateAdd is that you'll have to incorporate it into nested IIF's if I'm not mistaken. I imagine that will look real ugly.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    your excel formula does not match your requirement.

    your requirement says

    DateofReport + 22 years if Age is blank

    your formula says

    IF(Age=" ",DateofReport,

    so if blank, it is not adding 22 years

    Age is generally not a good value to use - it changes every year, better to use date or year of birth

    but you can use a formula along these lines

    Code:
    deletiondate=dateadd("yyyy",switch(isnull(age),22,age>=18,4,true,18-age),dateofreport)

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Dang! I keep forgetting about the switch function as opposed to nested IIF's.

  6. #6
    Ellen07886 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    2
    Quote Originally Posted by Bulzie View Post
    Research DateAdd Function for Access. you can add or subtract years, days, months, etc. to calculations. And yes you can create same type of formulas in Access.

    https://www.techonthenet.com/access/...te/dateadd.php

    Thanks. it looks a bit complicated but I'll have a go.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post 6 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Complex Multiple Math Calculations in a Query
    By MichaelA in forum Queries
    Replies: 3
    Last Post: 10-17-2019, 05:08 AM
  2. Replies: 2
    Last Post: 06-28-2017, 06:16 PM
  3. Replies: 19
    Last Post: 09-05-2014, 06:13 AM
  4. Replies: 7
    Last Post: 09-12-2011, 12:03 PM
  5. complex calculations like in Excel
    By jacko311 in forum Database Design
    Replies: 2
    Last Post: 11-11-2009, 05:51 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