Running Total in a Table: Step-by-Step Setup
In this article
Setting up a running total in a table lets you see a cumulative sum that updates as you add new rows. Instead of manually adding each new value to the previous total, a running total formula does it automatically. This guide covers the two most common ways to create one: using a simple formula in spreadsheet software (like Excel or Google Sheets) and using a calculated column in database tools (like SQL or Power BI). You'll need a table with at least one numeric column you want to sum, and a column that defines the order (like a date or an ID number).
What You'll Need
- A spreadsheet (Excel, Google Sheets, LibreOffice Calc) or a database tool (SQL, Power BI, Tableau).
- A table with data already entered, including a numeric column for the values you want to total.
- A column that gives a clear order to your rows (e.g., a date, a transaction ID, or a sequence number).
Step-by-Step
In Excel or Google Sheets
- Identify your data range. Make sure your table has a column with numbers (e.g., "Amount") and a column that sorts the rows (e.g., "Date" or "ID").
- Sort your data. If your running total should follow a chronological order, sort the table by that order column (e.g., sort by date ascending). This ensures the cumulative sum makes sense.
- Add a new column. Create a column header like "Running Total" in the first empty column to the right of your data.
- Enter the first formula. In the cell next to the first data row (e.g., C2), type a formula that references the first value. For example, if your amounts are in column B, enter
=B2(this is the starting total). - Enter the running total formula. In the cell below (C3), enter a formula that adds the current row's value to the previous running total:
=C2+B3. This is the core of the running total. - Fill down. Select the cell with the formula (C3), then double-click the small square at the bottom-right corner of the cell (the fill handle). This copies the formula down to the last row of your data. The formula will automatically adjust row references for each row.
- Verify the result. Check the last row's running total against a manual sum of all values (e.g., using
=SUM(B2:B10)) to confirm it matches.
In SQL (Window Function)
- Write your base query. Start with a SELECT that includes the column you want to total and the ordering column.
- Add the SUM window function. In the SELECT clause, add
SUM(your_numeric_column) OVER (ORDER BY your_order_column) AS running_total. For example:SELECT date, amount, SUM(amount) OVER (ORDER BY date) AS running_total FROM sales; - Run the query. The result set will include a running total column that accumulates as the order column increases.
- Add a partition if needed. If you want separate running totals for different groups (e.g., per product), add
PARTITION BY your_group_columninside the OVER clause:SUM(amount) OVER (PARTITION BY product_id ORDER BY date).
In Power BI (Calculated Column)
- Open the Data view. In Power BI, go to the table where you want the running total.
- Create a new column. Click "New Column" in the ribbon.
- Enter the DAX formula. Use a formula like . This sums all amounts where the date is less than or equal to the current row's date.
- Press Enter. The column appears with the cumulative total for each row.
Common Mistakes
- Not sorting the data first. A running total is only meaningful if the rows are in the order you want the sum to accumulate. If you skip sorting, the total will be random.
- Using an absolute reference incorrectly. In spreadsheets, if you use
$B$2instead ofB2in the fill-down formula, the reference won't change as you copy it, and you'll get the same value in every row. - Starting the running total at the wrong row. If you put the formula in the header row or skip the first data row, the total will be off by one.
- Including blank cells. If your numeric column has blank cells, the running total formula may treat them as 0, which is fine, but if you use a different formula that errors on blanks, you might see #VALUE!.
- Forgetting to update the range when adding new rows. In spreadsheets, if you insert a new row in the middle, the formulas may not extend automatically. Always check the fill handle covers new rows.
Tips
- Use a table object. In Excel, convert your data range to a Table (Ctrl+T). Then, when you add new rows, the running total formula will automatically extend to the new rows.
- For large datasets, use a PivotTable. If you need a running total for reporting, a PivotTable with a "Show Values As" > "Running Total In" can be faster and more flexible.
- In SQL, always include the ORDER BY in the window function. Without it, the running total is undefined.
- Use conditional formatting. Highlight the running total column to visually spot trends or thresholds.
- Test with a small dataset. Before applying to a huge table, test your formula on a few rows to ensure it behaves as expected.
Troubleshooting
- Running total doesn't update when I add a new row. In spreadsheets, if you're not using a Table, the formula range might not include the new row. Drag the fill handle down to cover the new row, or convert to a Table.
- I see #VALUE! or #REF! errors. This usually means a cell reference is broken (e.g., you deleted a column) or the formula is trying to add text. Check that all referenced cells contain numbers.
- The total is wrong after sorting. If you sort the data after creating the running total, the formula references will move with the rows, but the cumulative sum will now be based on the new order. Re-sort or re-enter the formula after sorting.
- In SQL, the running total is not cumulative. Ensure you have the ORDER BY inside the OVER clause. If you only have PARTITION BY, the sum will be the total for the whole partition, not a running total.
- In Power BI, the running total is blank for some rows. This can happen if the date column has blanks. Use a filter to exclude blank dates or use a different ordering column.
Frequently Asked Questions
Can I create a running total in Excel without a formula?
Yes, you can use a PivotTable. Drag the numeric field to the Values area, then right-click the field and choose "Show Values As" > "Running Total In" and select the base field (e.g., date).
How do I reset the running total when a new category starts?
In Excel, use a formula that checks if the category changes: =IF(A2=A1, C1+B2, B2). In SQL, use PARTITION BY the category column. In Power BI, use a similar IF in DAX.
Does the running total work with negative numbers?
Yes, the sum will decrease when a negative value is added. That's expected.
Can I use a running total for dates or text?
No, a running total is a numeric sum. For dates, you would need to convert them to numbers first (e.g., days since a start date).
Why does my running total in SQL start at 0?
If you use SUM(value) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), it should start at the first row's value. If it starts at 0, you might have a NULL value in the first row—use COALESCE to treat NULL as 0.
Is there a way to do a running total in Google Sheets with an array formula?
Yes, you can use =ARRAYFORMULA(SUMIF(ROW(B2:B), "<="&ROW(B2:B), B2:B)) to get a running total without dragging the formula down.