Running total
View on Wikipedia
This article relies on a single source. (February 2024) |
A running total or rolling total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, by adding the value of the new number to the previous running total. Another term for it is partial sum.
The purposes of a running total are twofold. First, it allows the total to be stated at any point in time without having to sum the entire sequence each time. Second, it can save having to record the sequence itself, if the particular numbers are not individually important.
Method
[edit]Consider the sequence (5, 8, 3, 2). What is the total of this sequence?
Answer: 5 + 8 + 3 + 2 = 18. This is arrived at by simple summation of the sequence.
Now we insert the number 6 at the end of the sequence to get (5, 8, 3, 2, 6). What is the total of that sequence?
Answer: 5 + 8 + 3 + 2 + 6 = 24. This is arrived at by simple summation of the sequence. But if we regarded 18 as the running total, we need only add 6 to 18 to get 24. So, 18 was, and 24 now is, the running total. In fact, we would not even need to know the sequence at all, but simply add 6 to 18 to get the new running total; as each new number is added, we get a new running total.
The same method will also work with subtraction, but in that case it is not strictly speaking a total (which implies summation) but a running difference; not to be confused with a delta. This is used, for example, when scoring the game of darts. Similarly one can multiply instead of add to get the running product.
Use
[edit]The concept of a running total is easily understood. It is common in many everyday uses. For example, most cash registers display a running total of the purchases so far rung in. By the end of the transaction this will, of course, be the total of all the goods. Similarly, the machine may keep a running total of all transactions made, so that at any point in time the total can be checked against the amount in the till, even though the machine has no memory of past transactions.
Typically many games of all kinds use running totals for scoring; the actual values of past events in the sequence are not important, only the current score, that is to say, the running total.
Tabulating machines had dedicated registers that could [only] accumulate running totals of numbers in preselected columns and display or print them.
It is trivial for computers to keep running totals in variables or registers. The central processing unit of computers for many years had one general-purpose register called the accumulator.[1]: 7 Most arithmetic operations stored their results into this one register. This accumulator, essentially, kept a running total; that is, it "accumulated" the results of individual calculations.
A betting accumulator is the running product of the outcomes of several bets in sequence.
See also
[edit]- Moving average a.k.a. running average
- Prefix sum
References
[edit]- ^ Programmed Data Processor-1 Manual (PDF). Maynard, Massachusetts: Digital Equipment Corporation. 1961. Archived (PDF) from the original on 9 October 2022. Retrieved 11 February 2024.
External links
[edit]- cumulative at Wiktionary (a related term)
Running total
View on Grokipediacumsum function, which computes the cumulative sum along specified dimensions of arrays. Similarly, in SQL and spreadsheet tools like Excel, window functions or formulas compute running totals to visualize progressive totals in datasets, aiding in financial reporting and performance metrics.[4] This versatility underscores the running total's role as a core tool for accumulation and progression analysis across disciplines.
Definition and Basics
Core Concept
A running total, also known as a cumulative sum, is the ongoing summation of a sequence of numbers or values, where each successive total is formed by adding the next value to the previous total.[1][5] This process creates a series of partial sums that build progressively, reflecting the accumulation up to any given point in the sequence.[6] The progression of a running total typically begins with an initial value, such as zero or a specified starting amount, and updates incrementally as each new data point is incorporated.[7] For instance, in a simple sequence of daily sales figures, the running total at the end of day one would be the first day's sales, on day two it would include the sum of the first two days, and so on, providing a snapshot of growth or accumulation at every stage.[8] This dynamic approach contrasts with a static sum, which computes the total of all values only once at the end, without intermediate results.[9] In practice, running totals often start from zero for neutral baselines in sequences like measurements or counts, though non-zero initials are used when accounting for pre-existing amounts, such as an opening balance in a ledger.[10] Such setups enable tracking of evolving totals in contexts like finance, where they monitor cumulative expenses over time.[5]Related Terminology
A running total is commonly referred to by several synonymous terms in mathematical and computational contexts, including "cumulative total," which emphasizes the progressive accumulation of values over time, and "cumulative sum," a standard term for the sequence of partial sums derived from an initial sequence.[1] The phrase "partial sum" specifically denotes the sum of elements up to a given point in the sequence, often used interchangeably in discrete mathematics to describe the building total.[1] It is important to distinguish a running total from related but distinct concepts, such as the moving average, which computes the arithmetic mean over a fixed sliding window of recent values rather than accumulating the entire sequence without bounds.[11] In computing, particularly in array-based algorithms, the prefix sum represents a specialized form of running total where each array element stores the cumulative sum from the array's start to that index, enabling efficient subarray sum queries.[12] Contextual variations of the term adapt to specific domains; for instance, in accounting, "running balance" describes the ongoing tally of debits and credits in a ledger, providing a real-time view of account status after each transaction.[13] In games and sports, "cumulative score" tracks the total points accumulated by participants across rounds or events, as seen in tournament leaderboards where overall performance is summed progressively.[14] Common misconceptions arise when conflating a running total with more complex aggregation methods; it is not a weighted sum, which assigns different multipliers to each addend to reflect varying importance, nor an exponential moving average, where older values receive exponentially decaying weights to prioritize recent data in time series analysis.[15]Mathematical Formulation
Cumulative Sum Equations
The running total, also known as the cumulative sum, for a discrete sequence is formally defined by the partial sum equationProperties and Variants
Running totals, defined as the partial sums $ S_k = \sum_{i=1}^k a_i $ for a sequence $ {a_i} $, exhibit several fundamental mathematical properties. One key property is monotonicity: if all terms $ a_i \geq 0 $, then the sequence of running totals $ {S_k} $ is non-decreasing, since each subsequent sum adds a non-negative value to the previous one. This follows directly from the construction of partial sums for series with positive terms, ensuring $ S_k \geq S_{k-1} $ for all $ k $. Another essential property is linearity: the cumulative sum operator is linear, meaning for scalars $ \lambda $ and constant vector $ \mathbf{b} $ (with all components equal to $ b $), $ S_k(\lambda \mathbf{a} + \mathbf{b}) = \lambda S_k(\mathbf{a}) + k b $. This linearity arises because summation distributes over scalar multiplication and addition. Regarding bounds and inequalities, for sequences with non-negative terms (assuming $ S_0 = 0 $), the running totals satisfy $ 0 \leq S_k \leq S_n $ for $ 1 \leq k \leq n $, where $ S_n $ is the total sum of the sequence. The minimum running total is $ S_1 = a_1 \geq 0 $, and the maximum is the overall sum $ S_n $, reflecting the cumulative nature of the process. In general sequences without positivity constraints, the minimum and maximum running totals depend on the prefix sums, but they always relate to the total sum as intermediate accumulations leading to $ S_n $. Variants of running totals extend the basic formulation to handle different scenarios. Signed running totals allow negative values in the sequence $ {a_i} $, resulting in potentially decreasing or oscillating $ S_k $, which is useful for modeling net changes such as account balances. Weighted running totals modify the sum to $ S_k = \sum_{i=1}^k w_i a_i $, where $ {w_i} $ are positive weights, often used in statistical control processes to emphasize certain terms. A continuous analog arises in calculus, where the running integral $ \int_0^t f(x) , dx $ serves as the continuous counterpart to the discrete running total, representing the accumulation of a function's values over an interval as the limit of Riemann sums. The running total uniquely determines the original sequence through finite differences: with $ S_0 = 0 $, $ a_1 = S_1 $ and $ a_k = S_k - S_{k-1} $ for $ k \geq 2 $, providing an invertible relationship between the two.Computation Methods
Manual and Step-by-Step Calculation
A running total, also known as a cumulative sum, is computed manually by initializing a total to zero and then sequentially adding each subsequent value in a list to the current total, recording the updated sum after each addition. This process ensures that each recorded value represents the accumulation up to that point in the sequence. To execute this step by step, first list the values in order, such as a sequence of five numbers: 10, 20, 5, 15, 30. Begin with an initial running total of 0 before the first value. Add the first value (10) to obtain 10, then add the second (20) to reach 30, followed by the third (5) for 35, the fourth (15) for 50, and the fifth (30) for 80. The results can be organized in a table for clarity:| Step | Value | Running Total |
|---|---|---|
| 0 | — | 0 |
| 1 | 10 | 10 |
| 2 | 20 | 30 |
| 3 | 5 | 35 |
| 4 | 15 | 50 |
| 5 | 30 | 80 |
| Step | Value | Running Total |
|---|---|---|
| 0 | — | 0 |
| 1 | 2 | 2 |
| 2 | 3 | 5 |
| 3 | -1 | 4 |
| 4 | 4 | 8 |
Programmatic Implementation
A running total, also known as a cumulative sum, can be implemented programmatically using a simple iterative approach in pseudocode. The basic algorithm initializes a variable to zero and accumulates the sum by iterating through the input list, appending the current total after each addition. For example:total = 0
result = []
for each item in input_list:
total += item
result.append(total)
return result
This pseudocode represents a straightforward loop-based method suitable for most programming contexts.[16]
In specific languages, implementations leverage built-in functions for efficiency. In Python, the NumPy library provides the numpy.cumsum() function, which computes the cumulative sum along a specified axis of an array, returning a new array with the running totals. For instance, import numpy as np; result = np.cumsum([1, 2, 3]) yields [1, 3, 6]. Alternatively, a manual loop mirrors the pseudocode above, using a list comprehension or for-loop to build the result.[17] In Microsoft Excel, a running total is created using the formula =SUM($A$1:A1) in a cell adjacent to the data column, then dragged down to apply it row-by-row; the absolute reference $A$1 fixes the starting point while the relative reference A1 expands with each row.[18] For SQL databases like SQL Server, the window function SUM(value) OVER (ORDER BY id ROWS UNBOUNDED PRECEDING) calculates the running total ordered by an identifier, partitioning if needed for grouped computations.[19]
These implementations exhibit O(n) time complexity, where n is the number of elements, as each item is processed exactly once in a single pass. Space complexity is O(n) when creating a new result array, though in-place modifications can reduce auxiliary space to O(1) by updating the original data structure directly.[16]
Edge cases must be addressed for robustness. For an empty input list, the function should return an empty result to avoid errors. Negative values are handled naturally by the addition operation, allowing the running total to decrease as needed. Floating-point inputs may introduce precision issues due to binary representation limitations, such as rounding errors in sums like 0.1 + 0.2 yielding 0.30000000000000004; using decimal types or rounding functions mitigates this in sensitive applications.[17]
For large datasets, optimizations focus on vectorized operations to leverage hardware acceleration. In NumPy, cumsum() performs element-wise accumulation in compiled C code, avoiding Python loop overhead and enabling parallelization on multi-core systems, which significantly speeds up processing for arrays with millions of elements compared to pure Python loops.[17]
Applications and Uses
In Finance and Accounting
In finance and accounting, running totals serve as a fundamental mechanism for tracking ongoing monetary flows and performance metrics over time, providing a cumulative view that reflects the net effect of transactions up to any given point. A primary application is in maintaining running balances on bank statements, where deposits are added and withdrawals subtracted sequentially to yield a continuously updated account balance, enabling real-time monitoring of liquidity and cash positions. Similarly, in financial reports, running totals aggregate revenue and profit figures across periods, such as monthly or yearly summaries, to illustrate growth trajectories and overall financial health without resetting at each interval. Regulatory standards like Generally Accepted Accounting Principles (GAAP) and International Financial Reporting Standards (IFRS) mandate the use of cumulative figures in balance sheets and income statements to ensure transparency and comparability in financial reporting. Under GAAP, for instance, retained earnings are presented as a running total of net income minus dividends, capturing the accumulated profits available for reinvestment.[20] IFRS similarly requires cumulative recognition of revenues and expenses in consolidated statements, with quarterly running totals often employed for interim fiscal tracking to comply with disclosure rules for public companies. These standards emphasize the accuracy of running totals to prevent misrepresentation of financial position. Accounting software such as QuickBooks integrates running totals directly into ledger functionalities to facilitate bank reconciliations, where transactions are matched against statements to verify the cumulative balance and identify discrepancies. This automation reduces manual errors and supports audit trails by maintaining a sequential record of adjustments. However, risks associated with running totals include the propagation of rounding errors in long-term tracking, where small discrepancies in decimal places can compound over numerous transactions, potentially leading to material misstatements in financial statements. Handling adjustments like reversals—such as voided checks or returns—requires careful retroactive updates to the running total to maintain integrity, often necessitating reconciliation protocols to mitigate these issues. The concept of running totals traces its origins to the emergence of double-entry bookkeeping in the 13th and 14th centuries among Italian merchants, which was later documented by Luca Pacioli in 1494. This historical innovation laid the groundwork for modern accounting practices reliant on sequential accumulation.In Statistics and Data Analysis
In statistics and data analysis, running totals play a crucial role in constructing cumulative distributions, such as the cumulative distribution function (CDF) in probability theory, which represents the running total of probabilities up to a given point, providing the probability that a random variable is less than or equal to that value.[21] This cumulative approach is essential for summarizing probabilistic outcomes and understanding the overall distribution shape. Similarly, in time-series analysis, running totals facilitate the identification of trends by accumulating values over time, such as tracking sales growth through cumulative monthly figures, which reveal patterns in sequential data like increasing or stabilizing volumes.[22] In quality control, cumulative sum (CUSUM) charts use running totals of deviations from a target to detect small shifts in process means, as introduced by E.S. Page in 1954.[23] A key technique involving running totals is the construction of the Lorenz curve, used to measure inequality in distributions like income or wealth, where the curve plots the cumulative proportion of the total (e.g., income) held by the bottom cumulative proportion of the population, ordered from lowest to highest.[24] This running accumulation highlights deviations from equality, serving as the basis for calculating the Gini coefficient, a summary statistic of inequality derived from the area between the Lorenz curve and the line of perfect equality; a Gini value closer to 0 indicates greater equality, while values near 1 signify high inequality.[25] Running totals are often visualized using line plots to illustrate accumulation over time or ordered categories, effectively showing how values build up and revealing trends in dashboards or exploratory analyses; for instance, tools like Tableau employ table calculations to generate these plots, connecting points to depict progressive totals in statistical summaries. When increments are non-negative, running totals exhibit a monotonic non-decreasing property that enhances trend insights by emphasizing persistent directions in data evolution without reversal.[22][26]Examples and Illustrations
Numerical Examples
A running total, also known as a cumulative sum, is computed by sequentially adding each new value to the previous total, starting from zero or the first value. The following examples demonstrate this process using simple sequences of numbers, illustrating key behaviors such as monotonic increase, fluctuations due to negative values, handling of decimals, and growth in longer sequences. Consider a basic sequence of positive integers: 5, 10, 7. The running totals are calculated as follows:| Step | Input Value | Running Total |
|---|---|---|
| 1 | 5 | 5 |
| 2 | 10 | 15 |
| 3 | 7 | 22 |
| Step | Input Value | Running Total |
|---|---|---|
| 1 | 100 | 100 |
| 2 | -20 | 80 |
| 3 | 30 | 110 |
| 4 | -5 | 105 |
| Step | Input Value | Running Total |
|---|---|---|
| 1 | 1.5 | 1.5 |
| 2 | 2.25 | 3.75 |
| 3 | 0.75 | 4.5 |
| Step | Input Value (Fibonacci) | Running Total |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 4 |
| 4 | 3 | 7 |
| 5 | 5 | 12 |