SF Logo
  • Magazine
    • Current Issue
    • Past Issues
    • Issues Archive
    • Digital SF
  • Topics
    • Measurement
    • Management
    • Reporting
    • Strategy
    • Governance
    • Ethics
    • Leadership & Careers
    • Technology
    • Small Business
    • IMA
  • BLOGS
    • SF Blogs
    • IMA Moments
    • SF Technotes
  • About Us
    • About SF
    • About IMA
    • Contact Us
    • Subscribe
    • SF Editorial Guidelines & Submissions
    • SF Media Kit For Advertisers

Technology |

ACCESS: RUNNING TOTALS

By Patricia Cox
October 30, 2015

From time to time, you might need to keep a running total in Access, especially if you’re working with financial or accounting data. It’s easy to create a running total within a report, but it’s more difficult to accomplish within a query.

 

For a report, you can simply set the Running Totals property of the appropriate text box to Overall. But if you want to, say, use the running totals elsewhere, calculate an account balance, or make a table with the running totals, you’ll need to have the running total data available in a query.

 

DSUM

 

One method is to use the DSUM function, which is a function that will calculate a sum of records in a table or query. It has three arguments:

 

  1. An expression that identifies the numeric field whose values you want to sum. It can be a string that identifies a field in a table or query, or it can be a calculation of the data in that field. You can use the name of a field in a table, a control on a form, a constant, or a function.

 

  1. A domain that identifies the set of records where the data is. It’s a string expression that can be a table or query name.

 

  1. The criteria that’s used to identify the range of data for the function to use. It’s also a string expression. Any field that’s included in the criteria must also be in the domain.

 

The expression and domain arguments are required. The criteria argument is optional.

 

EXAMPLE CASE

 

A good example of this strategy is calculating an account balance from debits and credits. Using the Transaction table in our database, we will use the DSUM function to calculate running totals for Debits and Credits and then subtract them to get the running total. Then we will use it to calculate the percent of total for the Debits.

 

Account Balance

 

The first step is to get the account balance. Create a query using the Transaction table as the data source. Add ID, Debit, and Credit to the design grid. In the fourth column, enter DebitRunningSum:DSum(“Debit”,“Transaction”,“ID <=” & [ID]) into the field. This will sum the Debit field in the Transaction table where the ID is less than or equal to the ID. This ensures the items are summed in order to get the running total. Run the query to make sure the totals are correct. Because of the function’s specific syntax, sometimes it can be a challenge to get all the quotes, brackets, and parentheses in the right spot.

 

In the next field, add CreditRunningSum: DSum(“Credit”,“Transaction”,“ID <=” & [ID]). This will sum the Credits field. Run the query again to test that the field is totaling properly.

 

Finally, add Balance: [CreditRunningSum]-[DebitRunningSum] in the next field. This will subtract the Credits from the Debits, yielding the balance. Test the query, then save it as “Running Sum Balance” and close it. See Table 1 for a list of the fields included in the query.

 

Print

 

Total

 

Next, before we are able to create a query to calculate the percent of total of the Debits, we first need to create a query to get the total. This is a simple query that sums Debit. Create a query with the Transaction table as the source, and add the Debits field. Click the Totals button so the line appears in the design grid, and set it to Sum. Save the query as “Total.”

 

Running Totals and Percent Total

 

Now we’re ready to calculate the running totals and the percent of total. Create a query using both the Transaction table and the Total query as data sources. Add ID, Date, and Debit fields to the query. Set the Criteria for the Debit field to “Is Not Null.” In the next field, add DebitRunningSum:DSum(“Debit”,“Transaction”,“ID <=” & [ID]). Test the query to make sure all the details are right. You also could copy this syntax from the first query we made.

 

In the next field, enter PercentTotal: DSum(“Debit”,“Transaction”,“ID <=” & [ID])/[SumOfDebit]. This will divide the running totals by the overall total from the Total query. On the Property Sheet, set the field’s format property to Percent.

 

Save the query as “Running Sum Percent Total.” Test and close the query. Table 2 shows the fields and criteria used for this query.

 

Print

 

NEXT MONTH

 

I am retiring from writing this column at the end of the year, which means next month will be my final column. It has been my privilege sharing Access strategies with you for these last seven years. I have been thinking about what to write in the final column, and as my final guidance for you, I gathered together a set of strategies from the last seven years to help as you move forward in your use of this powerful tool.

 

Download this month’s database here: SF_NOV_2015.SF_NOV_2015

 

SF BEST PRACTICES

 

When using a new function for the first time, be sure to understand the arguments clearly and apply them to the data in your tables and queries. Test thoroughly and keep trying until the function works.

Patricia Cox has taught Excel and Access to management accounting students and other college majors and has consulted with local area businesses to create database reporting systems since 1998. She also is a member of IMA’s Madison Chapter. To send Patricia a question to address in the Access column, e-mail her at kathrynmann@tds.net.
5 + Show Comments
5 comments
    Nelson chavez May 16, 2018 AT 3:54 pm

    This topic is very interesting for me.

    Tom Klecker December 20, 2017 AT 6:51 pm

    The running balance in the example shows #error on firs line due to null value of the debit or credit.

    my solution was to insert iif statements with an isnumeric function that replace a null debit or credit running total with 0 (zero) like this:
    Balance: IIf(IsNumeric([CreditRunningSum])=0,0,[CreditRunningSum])-IIf(IsNumeric([DebitRunningSum])=0,0,[DebitRunningSum])

    there may be a more efficient fix.

    john mack December 14, 2017 AT 1:09 pm

    This doesn’t work in 2016

    oras July 20, 2016 AT 12:31 pm

    thanks

    Nahed Abed December 6, 2015 AT 11:46 am

    Thank you

Comments are closed.

You may also like

ACCESS: LINKING DATA IN QUERIES

Access: Enhancing a Menu

ACCESS: BREAKING UP TEXT

Access: 12 Ways of Access

August 2022
Subscribe To SF Magazine
MORE ON

Leadership & Careers

Are You Promotable?

IMA

Gwen Van Berne: Breaking Boundaries

Governance

An Internal Controls Mindset for Excel

Ethics

Ethics and Controls at Accountable Coffee Co.

Strategy

ESG in the Accounting Curriculum

SF Magazine

  • Current Issue
  • Past Issues
  • Past Issues Archive

Topics

  • CARL MENCONI CASE WRITING COMPETITION
  • Ethics
  • Governance
  • IMA
  • IMA PULSE

Topics

  • Leadership & Careers
  • Management
  • Measurement
  • Reporting
  • Small Business

Blogs

  • IMA Moments
  • IMA Pulse
  • SF Technotes
  • ABOUT SF
  • ABOUT IMA
  • SF EDITORIAL GUIDELINES & SUBMISSIONS
  • CONTACT US
  • SUBSCRIBE
  • MEDIA KIT FOR ADVERTISERS
  • IMA COOKIE POLICY
  • IMA PRIVACY POLICY
  • IMA TERMS AND CONDITIONS
© 2015 - 2022, Institute of Management Accountants, Inc.
10 Paragon Drive, Suite 1, Montvale, NJ 07645-1760
(800) 638-4427 or +1 (201) 573-9000