Results 1 to 5 of 5
  1. #1
    mbelc is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2016
    Posts
    8

    If-Then Formula for Calculated Field in Access

    Hi,

    I'm sorry to post again, but I am just wondering if it is possible to build an expression that is of the following sort:

    Field 3 is where I want the number to show up.

    If [Field 1]=x, I want Field 3 to calculate/show the result of [Field 2]*3. If [Field 1]=y, I want Field 3 to calculate/show the result of [Field 2]*5.

    How do I build an expression like this? (I am only familiar with excel formulas and the one I use in excel did not work for this).

    Thanks

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    calculated fields in tables are generally a bad idea - just because you can doesn't mean you should

    but if you want to go that route, in access you use IIF rather than IF i.e. (I'm assuming field1 can only be x or y)

    iif([Field 1]="x",[Field 2]*3,[Field 2]*5)

    or

    [Field 2]* iif([Field 1]="x",3,5)

  3. #3
    mbelc is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2016
    Posts
    8
    Quote Originally Posted by Ajax View Post
    calculated fields in tables are generally a bad idea - just because you can doesn't mean you should

    but if you want to go that route, in access you use IIF rather than IF i.e. (I'm assuming field1 can only be x or y)

    iif([Field 1]="x",[Field 2]*3,[Field 2]*5)

    or

    [Field 2]* iif([Field 1]="x",3,5)
    Very helpful, thanks so much!

    Though I am wondering why you think calculated fields are a bad idea?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by mbelc View Post
    I'm sorry to post again
    Don't be; it would be a boring site without people posting questions.

    In addition to whatever thoughts Ajax may have:

    http://allenbrowne.com/casu-14.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    No, Allen pretty much has it.

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

Similar Threads

  1. Replies: 19
    Last Post: 07-13-2015, 10:15 AM
  2. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  3. Replies: 2
    Last Post: 12-30-2014, 01:32 PM
  4. In access form sum of calculated field
    By pgdeval in forum Access
    Replies: 1
    Last Post: 10-27-2014, 02:07 AM
  5. Back in ACCESS 2007 Calculated field in query
    By djcmalvern in forum Queries
    Replies: 5
    Last Post: 04-30-2013, 09:28 AM

Tags for this Thread

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