## Running totals

The SUM function in cell D3 uses only a single cell reference and still manages to sum current and previous values in column D. Read on to find out how.

**The formula in cell D3:**

The SUM function has a cell reference that consists of two parts, the first part has a dollar sign before the column character and another one before the row number.

The dollar sign tells you that the cell reference is locked and won't change if you copy the formula. In Excel terminology: an absolute cell reference.

However, the second part of the cell reference has no dollar signs and that part changes when you copy and paste the formula to other cells. In Excel terminology: a relative cell reference.

What happens when you copy the cell and paste to cell D4?

The second part of the cell reference now points to cell C4 and the first part is still pointing to cell C3. The cell reference expands as you copy the formula to cells below.

If you want to learn more about absolute and relative cell references, read the following article:

**How to use absolute and relative references in excel**

Comments(12) Filed in category: Excel

The following article explains Excel's SUM function in greater detail:

Comments(0) Filed in category: Excel, SUM function

### Running totals with a condition

The formula above in column D calculates running totals based on a condition. The condition changes depending on the value in column B.

**Example 1**, in cell D6 the formula calculates the sum for Item C. Item C is only in cell B6, the corresponding value in column C is B6. The formula returns 2000 in cell D6.

**Example 2**, in cell D7 the formula calculates the sum for Item A. Item A is in cell B3, B4 and B7, the corresponding values in column C are C3,C4 and C7.

4000 + 6000 + 1000 = 11000

The formula returns 11000 in cell D7. There are several ways to calculate a running total based on a condition, the easiest and smallest formula is probably the SUMIF function.

**Formula in cell D3:**

The arguments in a SUMIF function are: **SUMIF(***range*, *criteria*, [*sum_range*]**)**

The *range* argument* *grows when the formula is copied to cells below. $B$3:B3 changes to $B$3:B4 when the formula is copied to cell D4. This applies to the [*sum_range*] argument as well.

The expanding cell references make this formula include more and more cells and allowing it to calculate running totals based on a condition.

### Running totals on a monthly basis

**Formula in cell D3:**

The dates in column B are sorted in an ascending order, however, the formula works fine for dates sorted in a descending order as well.

The formula in column D adds amounts to a running total using the corresponding date as a condition.

Example, the formula in cell D6 uses this text string "2017-10" in cell B6 as a condition to add all previous amounts above cell D6 that also return text string "2017-10".

In other words, the formula creates a running total for the current month and starts all over when a new month begins.

#### Explaining formula in cell D8

Note that I am explaining the formula in cell D8, not cell D3.

**Step 1 - Convert corresponding date to a text string**

TEXT(B8, "YYYY-MM") returns 2017-11

In this case, the TEXT function converts a date to a particular format specified in the second argument. YYYY returns the year and MM returns the month number.

**Step 2 - ***Co*nvert corresponding dates to text strings

TEXT($B$3:B8, "YYYY-MM") returns the following array {"2017-10";"2017-10";"2017-10";"2017-10";"2017-11";"2017-11"}

The first argument in the TEXT function is a cell range containing multiple values. The TEXT function returns an array with the exact same number of values.

**Step 3 - Build a logical expression**

TEXT(B8, "YYYY-MM")=TEXT($B$3:B8, "YYYY-MM")

becomes

2017-11={"2017-10";"2017-10";"2017-10";"2017-10";"2017-11";"2017-11"}

and returns {FALSE; FALSE; FALSE; FALSE; TRUE; TRUE}

**Step 4 - Multiply with amounts**

(TEXT(B8, "YYYY-MM")=TEXT($B$3:B8, "YYYY-MM") )*$C$3:C8

becomes

{FALSE; FALSE; FALSE; FALSE; TRUE; TRUE}*{70;170;210;280;60;160;240}

and returns {0; 0; 0; 0; 60; 100}

**Step 5 - Sum values**

SUMPRODUCT((TEXT(B3, "YYYY-MM")=TEXT($B$3:B3, "YYYY-MM"))*$C$3:C3)

becomes

SUMPRODUCT({0; 0; 0; 0; 60; 100})

and returns 160 in cell D8.

Recommended article:

**Running totals within date range**

Comments(9) Filed in category: Excel, SUMPRODUCT function

### Display a running total when month changes

**Formula in cell D3:**

The picture above shows a formula in column D that shows the running total if the next cell in column B contains a new month.

#### Explaining formula in cell D7

Note, I will explain the formula in cell D7. The cell references have changed, the formula now looks like this:

Why will I explain the formula in cell D7? Not much is happening in D3, D4, D5 and D6.

**Step 1 - Check if month is not equal to month in cell below**

In this example, the TEXT function converts a date to a particular format specified in the second argument. YYYY returns the year and MM returns the month number.

TEXT(B7, "YYYY-MM")<>TEXT(B8, "YYYY-MM")

becomes

"2017-10"<>"2017-11"

and returns TRUE.

**Step 2 - Convert corresponding date to a text string**

TEXT(B7, "YYYY-MM") returns 2017-10

**Step 3 - ****Convert corresponding dates to text strings**

TEXT($B$3:B7, "YYYY-MM") returns the following array {"2017-10";"2017-10";"2017-10";"2017-10";"2017-10"}

The first argument in the TEXT function is a cell range containing multiple values. The TEXT function returns an array with the exact same number of values.

**Step 4 - Build a logical expression**

TEXT(B7, "YYYY-MM")=TEXT($B$3:B7, "YYYY-MM")

becomes

2017-10={"2017-10";"2017-10";"2017-10";"2017-10";"2017-10"}

and returns {TRUE; TRUE; TRUE; TRUE; TRUE}

**Step 5 - Multiply with amounts**

(TEXT(B7, "YYYY-MM")=TEXT($B$3:B7, "YYYY-MM") )*$C$3:C7

becomes

{TRUE; TRUE; TRUE; TRUE; TRUE}*{70;100;40;60;70}

and returns {70;100;40;60;70}

**Step 6 - Sum values**

SUMPRODUCT((TEXT(B7, "YYYY-MM")=TEXT($B$3:B7, "YYYY-MM"))*$C$3:C7)

becomes

SUMPRODUCT({70;100;40;60;70})

and returns 340 in cell D8.

### Download excel *.xlsx file

### Category: Sum function

Identify numbers in sum using solver

Here is a useful feature I recently found googling for Excel solver examples. I have summed some random values from […]Comments(48) Filed in category: Combinations, Excel, Solver, SUM function

Sum values between two dates with criteria in excel

In this post, I will provide a formula to sum values in column (Qty) where an column (Date) meets two […]Comments(27) Filed in category: Excel, SUM function

Sum values in a range where adjacent cell value equals a criterion

Question: How do I sum all values in a range where adjacent cell value equals a criterion? The criterion is […]Comments(19) Filed in category: Excel, SUM function

Comments(13) Filed in category: Excel, MMULT function, Permutations, SUM function

Filter unique distinct list sorted based on sum of adjacent values [Array Formula]

Table of Contents Filtering unique distinct text values and sort them based on sum of adjacent values Filtering unique distinct […]Comments(11) Filed in category: Excel, SUM function

Comments(7) Filed in category: Count values, Excel, MMULT function, SUM function

Excel udf: Find positive and negative amounts that net to zero

I created/modified an udf to solve his question: Find positive and negative amounts that net to zero in excel Question:I would […]Comments(5) Filed in category: Excel, SUM function

Comments(2) Filed in category: Excel, SUM function

Comments(2) Filed in category: Check-boxes, Excel, SUM function

Excel udf: Find numbers in sum

This article describes how to find a sum from a range of numbers using a user defined function. Let´s see […]Comments(2) Filed in category: Excel, Finance, SUM function