Results 1 to 4 of 4
  1. #1
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71

    Derived Column with SQL equation and IIF

    Hello,

    I have a table called 'survey' which has three columns (amongst others) called q9, q9unitoftime, and q9numsperyear. Q9numsperyear is a derived column from the other two. I wrote an update query to make this work.

    UPDATE survey SET q9numsperyear=


    (Iif(q9unitoftime=1, q9*52, Iif(q9unitoftime=2, q9*12, Iif(q9unitoftime=3, q9))));

    This is good for a one time update, but I want access to perform that calculation on its own once q9 and q9unitoftime have been entered through a form.

    Can I do something like this on an event or something?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    The simple answer is do not store calculated values on your table. There is no reason to do it from the example you've provided. When you start reporting or doing data analysis through queries then you can perform the calculation. I'd really strongly recommend you not store the value you're after.

    If you are absolutely adamantly going to do this regardless of good practice you can use that same formula if you are using a bound form you would just set the ON EXIT event of your two calculation fields to the same thing

    q9numsperyear=
    (Iif(q9unitoftime=1, q9*52, Iif(q9unitoftime=2, q9*12, Iif(q9unitoftime=3, q9))));

    Where SQnumsperyear is the name of the bound control on your data entry form.

  3. #3
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    Yeah, I know you're not supposed to store derived values. I thought about that when I was doing it. The reason that I did was because I needed to get the average of all those values, and I couldn't think of how do AVG(something) without them being stored somewhere. If there is a better way to do that, I will definitely not store them anymore.

    Thanks for your help!

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if you're putting the data on a report you can average items on a group or over the entire data set you'd just have a formula in a text box in your group or report footer that was

    =sum([fieldname])/count([fieldname])

    where fieldname would be a numeric field

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

Similar Threads

  1. A new equation problem
    By stryder09 in forum Access
    Replies: 2
    Last Post: 03-23-2011, 02:28 PM
  2. still having equation problem
    By stryder09 in forum Access
    Replies: 16
    Last Post: 02-19-2011, 12:13 AM
  3. Another equation almost done now
    By stryder09 in forum Access
    Replies: 4
    Last Post: 02-18-2011, 12:18 PM
  4. Another equation question
    By stryder09 in forum Access
    Replies: 3
    Last Post: 02-17-2011, 11:41 AM
  5. Calulating derived date in table
    By hedleyw in forum Access
    Replies: 2
    Last Post: 04-12-2009, 02:33 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