Use the Sum and DSum functions to calculate the sum the values in a field in a domain, such as a query. Use the Sum function when writing SQL statements, and the DSum function when writing Visual Basic for Applications (VBA) code, macros, and expressions. Note that you can't use these functions in a data access page (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.). Additionally, you can't use the DSum function in an Access project (.adp).
| Expression |
Description |
| Sum([Freight]) |
Displays the sum of the values of the Freight field. |
| Sum([UnitPrice]*[Quantity]) |
Displays the sum of the product of the UnitPrice and Quantity fields. |
| [Sales] / Sum([Sales]) * 100 | Displays the percentage of sales, determined by dividing the value of the current record's Sales figure by the sum of all the values in the Sales field. Note If the control's Format property is set to Percent, don't include the "*100" portion.
|
| DSum("[Freight]", "Orders", "[ShipCountry] = 'UK'")
| Displays the sum of the values in the Freight field for orders shipped to the United Kingdom. The domain is the Orders table. |
Related Office Online discussions
Read related questions and answers from other Microsoft Office customers.