Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17

    =iff statement using date parameters

    Hi,



    I am trying to create a formula in an existing query. If the date value referenced (lets say 07/13/2018) is less than or equal to today's Date() the system needs to perform the calculation of a specific multiplier being applied to a field in the table.

    So for example, here is the basis of what I am trying to accomplish minus the important syntax:
    =iff(Today’s Date <= '07/13/2018’, [PP Deduction] * 13

    else
    =iff(Today’s Date <= ‘07/27/2018’,[PP Deduction] * 12
    And then continue this on for 12 other date values that have a different multiplier value.

    Is this possible?

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    you can put these dates into a table:
    TargDate, Multi
    07/13/2018, 13
    07/27/2018, 12
    etc

    then your query would use it to pull the Multiplier and do your math.
    Is this what you need or do the dates change too much to do this?

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Try =Iif([Date1]<=Date,[PP_Deduction]*13,iif([Date2]<=Date,[PP_Deduction]*12,IIf([Date3]<=Date,[PP_Deduction]*11,IIF([Date4]<=Date,[PP_Deduction]*10,........))))))))))))))

    Cheers,
    Vlad

  4. #4
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17
    Thanks for your assistance. Vlad - I tried the formula, and keep getting a 'enter parameter value' when running the formula on the date 7/13/2018. Is there a specific date function I need to do?

  5. #5
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17
    Ranman - that was actually the first thing I tired doing, making a seperate table with the date and multiplier in columns. I could not figure out how to make the query reference those values in the table however. Any suggestions? Thanks so much!

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Can you post what you tried?
    Vlad

  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,521
    I would go with ranman's solution, but have both start and end dates in the table. Then you can just join to that table in your query (non-equi join). Vlad's solution could work, but I can't recall what the nesting limit it and that may hit it. The table would be more flexible anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17
    Hi Vlad,

    I am trying to use the Iif statement with one multiplier just to see if that functions, trying the following:

    =Iif([07/13/2018]<=Date,[PP_Deduction]*13,"Test")

    Thanks

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Vlad looks to be offline. The syntax would be:

    =Iif(#07/13/2018# <= Date(),[PP_Deduction]*13,"Test")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Thanks Paul!

    patchesohouli, my original formula assumed you would have date fields in your table(s) that you would like to compare with today's date (returned by the Date() function). That is why I used the field delimiters (the square brakets). If you want to compare hard-coded dates simply enclose them in # as shown by Paul above. I believe the max number of nested IIf statements is around 14 so it should work for you, if not you can use the Switch function(https://www.techonthenet.com/access/...ced/switch.php) or even better a custom VBA function. If you provide us with more info regarding your specific issue we would be in a much better position to help. Are the dates static, are they record specific, etc.

    Cheers,
    Vlad

  11. #11
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17
    Thank you everyone for your quick replies! This was really helpful for my understanding. The =Iif statement is working perfectly, though I am going to look at the 'Switch Function' to try and understand that method as well.

    Thanks!

  12. #12
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17
    I am trying to adjust part of the formula for another application to look BETWEEN a range of numbers. I tried the following formula and many iterations of syntax, but am having difficulty getting it to work:

    =Iif(Date()>=#07/13/2018# and <=#07/29/2018#),[Flex Med/PP]*13,"Test")

    Does anyone know what is incorrect in this statement? Thanks

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would still recommend a table, but:

    =Iif(Date()>=#07/13/2018# and Date() <=#07/29/2018#),[Flex Med/PP]*13,"Test")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    patchesohouli is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    17
    I am getting a 'The expression you entered has a function containing the wrong number of arguments' prompt when I enter the above code. Any ideas? Thanks!

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I didn't notice you had an extra parentheses in there. Try:

    =Iif(Date()>=#07/13/2018# and Date() <=#07/29/2018#,[Flex Med/PP]*13,"Test")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. SQL statement from passed Parameters
    By Rpschwar in forum Access
    Replies: 9
    Last Post: 09-29-2017, 04:03 PM
  2. Parameters (Date Range) not working
    By smarty84handsome in forum Reports
    Replies: 4
    Last Post: 07-24-2013, 11:36 AM
  3. Open Report with Date Parameters
    By Gee in forum Access
    Replies: 12
    Last Post: 02-27-2013, 03:17 PM
  4. Query help. IIF Statement, a few parameters.
    By parkerjallen in forum Queries
    Replies: 2
    Last Post: 11-15-2012, 09:04 AM
  5. Date Parameters
    By pj13 in forum Reports
    Replies: 2
    Last Post: 02-01-2012, 01:12 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