How do I add a calcalated column in a table using other columns?

G

Guest

Is there a way to use a formula to calculate the value of a column using the
values from other columns within the same table and rows?

ie.
I have 5 columns: Acct#, value1, value2, value3, grand total.
Is there a way for me to have the grand total to sum up from value 1-3?
 
J

John W. Vinson

Is there a way to use a formula to calculate the value of a column using the
values from other columns within the same table and rows?

ie.
I have 5 columns: Acct#, value1, value2, value3, grand total.
Is there a way for me to have the grand total to sum up from value 1-3?

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.

To do so create a Query based on your (four column!) table, and in a vacant
Field cell type

GrandTotal:NZ([Value1]) + NZ([Value2]) + NZ([Value3])

The NZ function is Null To Zero - it will handle the case when there is no
data in one of the fields, which would otherwise give a NULL result.

Note that if you actually have fields named Value1, Value2 and Value3 you may
need to consider restructuring your table. "Fields are expensive, records are
cheap" - if you have a one (account) to many (value) relationship, two tables
in a one to many relationship is a better design.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top