Calculate Purchase Balances from Related Access Tables
Question details
The user needs to calculate the remaining balance for individual purchases by subtracting total payments from the purchase price across related database tables.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Managing a database where purchase records and payment transactions are stored in separate, related tables, requiring a way to view the current outstanding balance.
- Observed behavior
- The user is looking for the best method to calculate and display the remaining balance for each purchase record on a form or subform dynamically.
Ensure that your Purchases table and Payments table share a common key field, such as a PurchaseID, so they can be reliably linked together in a query.
Calculate Balances Using a Totals Query
Create a query to group and sum the payments, then join it to your purchases table to calculate the balance dynamically without storing it.
In relational database design, storing calculated values (such as a running balance) directly in a table is heavily discouraged. If a past payment is altered or deleted, a stored balance can easily become inaccurate.
Instead, the best practice is to calculate the balance on demand using a totals query. You can then use this query as the record source for your forms and reports.
Go to the Create tab on the Access ribbon and click 'Query Design'. Add your Payments (or Transactions) table. Add the 'PurchaseID' and 'PaymentAmount' fields to the grid. Click the 'Totals' button in the ribbon. Set the Total row for 'PurchaseID' to 'Group By' and for 'PaymentAmount' to 'Sum'. Save this query as 'qryTotalPayments'.
Create a new query in Design View. Add your 'Purchases' table and the 'qryTotalPayments' query you just created. Click and drag the 'PurchaseID' field from the Purchases table to the PurchaseID field in the query to establish a relationship (INNER JOIN).
Add the necessary fields from your Purchases table to the grid (like Price). In a blank column, type the following expression: `Balance: [Purchases].[Price] - Nz([qryTotalPayments].[SumOfPaymentAmount], 0)`. The Nz function ensures that if a purchase has zero payments, the calculation still evaluates properly instead of returning blank.
Save this combined query. Open your desired form in Design View, open the Property Sheet, and change the 'Record Source' to your newly saved query. You can now drag the calculated 'Balance' field onto your form.

Track Purchases and Balances Easily with WPS Office
While Microsoft Access provides powerful relational database tools, tracking simple purchases, payments, and balances is often much faster and more intuitive in a spreadsheet. WPS Office provides a free, lightweight spreadsheet application that makes financial tracking seamless.
- 1. Download and Install WPS Office: Visit the official WPS Office website to download and install the free, all-in-one suite on your PC or Mac.
- 2. Open WPS Spreadsheet: Launch the application and select 'Spreadsheet' to open your existing Excel workbooks or start a new financial tracking template.
- 3. Use Formulas for Balances: Easily subtract total payments from purchase prices using the SUMIF function to pull data across multiple tracking sheets without writing complex SQL queries.

Frequently Asked Questions
Why shouldn't I store the calculated balance directly in my Access table?
Storing calculated values in a table breaks database normalization rules. If a payment amount is updated, added, or deleted later, the statically stored balance field will not automatically update, leading to data inconsistencies. Using a dynamic query ensures the balance is always perfectly accurate.
Why am I getting a syntax error near INNER JOIN in my Access query?
Syntax errors near an INNER JOIN often occur if parentheses are missing when joining more than two tables, or if the data types of the joined fields do not match (e.g., trying to join a Short Text field to a Number field). Double-check your relationships and SQL view syntax.
How can I show a query's calculated balance automatically on my form?
Once you have created your totals query that calculates the balance, open your form in Design View. Go to the Property Sheet, look for the 'Data' tab, and set the 'Record Source' to your new query. You can then open the 'Add Existing Fields' pane and drag your calculated balance field directly onto the form.




