A calculated field is a field whose value is produced using an expression or formula. In Microsoft Access, calculated values can be created in queries, forms, and reports to perform calculations such as totals, discounts, balances, and percentages.
A calculated field uses existing field values, constants, operators, and functions to produce a result.
| StudentName | TotalFees | PaidFees | PendingFees |
|---|---|---|---|
| Amit | 10000 | 6000 | 4000 |
| Priya | 8000 | 5000 | 3000 |
| Rahul | 12000 | 9000 | 3000 |
PendingFees can be calculated by subtracting PaidFees from TotalFees:
PendingFees: [TotalFees]-[PaidFees]
The expression calculates the remaining fees for each student when used in a query.
Follow these steps to create a calculated field:
PendingFees: [TotalFees]-[PaidFees]
Here, PendingFees is the calculated column
name. The expression subtracts PaidFees from TotalFees.
Arithmetic operators allow you to perform calculations using numeric fields.
| Operator | Purpose | Example |
|---|---|---|
| + | Addition | [Price]+[Tax] |
| - | Subtraction | [TotalFees]-[PaidFees] |
| * | Multiplication | [Quantity]*[UnitPrice] |
| / | Division | [TotalMarks]/[Subjects] |
TotalPrice: [Quantity]*[UnitPrice]
If Quantity is 5 and UnitPrice is 200, TotalPrice will be 1000.
AverageMarks: [English]+[Hindi]+[Computer]
This expression adds the three marks. To calculate the average, divide the total by three:
AverageMarks: ([English]+[Hindi]+[Computer])/3
Calculated fields can be used to calculate discounts on product prices or course fees.
DiscountAmount: [Price]*10/100
If Price is 2000, DiscountAmount will be 200.
FinalPrice: [Price]-([Price]*10/100)
If Price is 2000, the final price after a 10% discount will be 1800.
DiscountAmount: [CourseFees]*[DiscountPercent]/100
FinalFees: [CourseFees]-([CourseFees]*[DiscountPercent]/100)
This example assumes DiscountPercent stores a number such as 10 for a 10% discount.
You can calculate tax amounts using a calculated field.
GSTAmount: [Price]*18/100
PriceWithGST: [Price]+([Price]*18/100)
If Price is 1000, GSTAmount will be 180 and PriceWithGST will be 1180.
You can write calculated expressions directly in an Access SQL query.
SELECT StudentName,
TotalFees,
PaidFees,
[TotalFees]-[PaidFees] AS PendingFees
FROM Students;
The AS keyword assigns the calculated result the column name PendingFees.
SELECT ProductName,
Quantity,
UnitPrice,
[Quantity]*[UnitPrice] AS TotalPrice
FROM Products;
This query calculates the total price for each product using Quantity and UnitPrice.
SELECT StudentName,
([English]+[Hindi]+[Computer])/3 AS AverageMarks
FROM Students;
This query calculates the average of the three subject marks for each student.
The IIf() function checks a condition and returns one value if the condition is true and another if it is false.
IIf(condition, value_if_true, value_if_false)
Result: IIf([Marks]>=40,"Pass","Fail")
If Marks is 40 or more, the result is Pass. Otherwise, the result is Fail.
FeeStatus: IIf([PaidFees]>=[TotalFees],"Paid","Pending")
This expression returns Paid when PaidFees is greater than or equal to TotalFees. Otherwise, it returns Pending.
Calculated controls can also be created in forms and reports to display totals, balances, and other derived values.
To calculate pending fees in a form or report, set the control's Control Source property to:
=[TotalFees]-[PaidFees]
=[English]+[Hindi]+[Computer]
=([ObtainedMarks]/[MaximumMarks])*100
These expressions calculate values for display. A calculated text box does not automatically store the result in a table field.
AverageMarks: IIf([MaximumMarks]=0,Null,[ObtainedMarks]/[MaximumMarks]*100)
This expression returns Null when MaximumMarks is zero and calculates the percentage otherwise.
Create a table named Students with these fields:
Goal: Practice arithmetic expressions, calculated columns, and conditional calculations in MS Access.
1. Which expression calculates pending fees?
2. Which function checks a condition and returns one of two values?
3. Does a calculated query column automatically store its result in the source table?