## Running totals based on criteria

Andrew asks:

LOVE this example, my issue/need is, I need to add the results. So instead of States and Names, I have to **match a client name**, and **add all the sales totals**:

clientA 10

clientA 10

clientA 10

clientB 5

clientB 5

clientB 5

So if I search for clientA, I need one cell that keeps a running total as sales are added. Lastly,** a date range** will need to be given, so search for sales from clientA between two dates and** keep a running total**...

**Table of Contents**

## 1. Running totals based on criteria - formula

The image above demonstrates a formula in cell E3 that calculates a running total based on a date range specified in cells H2, H3, and a condition specified in cell H4.

Formula in cell E3:

### Explaining the formula in cell E3

#### Step 1 - Populate SUMIFS function arguments

The SUMIFS function adds numbers based on criteria.

Function syntax: SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2], [criteria2], ...)

sum_range - $D$3:D3

criteria_range1 - $C$3:C3

criteria1 - $H$4

[criteria_range2] - $B$3:B3

[criteria2] - "<="&$H$3

[criteria_range3] - $B$3:B3

[criteria3] - ">="&$H$2

Cell reference $D$3:D3 contains an absolute part $D$3 indicated by the dollar signs and a relative part D3. This makes the cell reference grow when the cell is copied to the cells below.

This is also the case with $C$3:C3 and $B$3:B3, this makes the formula include more and more cells in columns B, C, and D creating the running total effect.

The less than, greater than, and equal sign shown in "<="&$H$3 and ">="&$H$2 let you create a condition so that the date range criteria are met.

The third condition is specified in cell $H$4, it makes sure that the running total is only valid for "Client D".

SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2], [criteria2], [criteria_range3], [criteria3], ...)

becomes

SUMIFS($D$3:D3,$C$3:C3,$H$4,$B$3:B3,"<="&$H$3,$B$3:B3,">="&$H$2)

#### Step 2 - Evaluate SUMIFS function

SUMIFS($D$3:D3,$C$3:C3,$H$4,$B$3:B3,"<="&$H$3,$B$3:B3,">="&$H$2)

becomes

SUMIFS(550,"Client D","Client D",40544,"<=40574",40544,">=40544")

and returns

550.

## 2. Running totals based on criteria - formula and Excel Table

I highly recommend a pivot table for this task, however, this article demonstrates a formula combined with an Excel defined table. A pivot table is lightning fast if you have lots of data to work with and is easy to learn.

The Excel Table is great for a list that keeps growing, the references to the Excel Table don't change which makes the formula easy to use. There is no need to adjust cell references, they are called structured references and are only used in Excel Tables.

This example shows how to calculate a running total using a formula based on a date range and a condition. This example is different from the one in section 1, it calculates a total for all data in the Excel Table. You can add more data to the Excel Table and the formula adjusts automatically creating a running total.

Formula in cell G6:

The SUMIFS function was introduced in Excel 2007, use the SUMPRODUCT function if you have an earlier Excel version.

### How to create an Excel defined table

- Select a cell in the data set.
- Press CTRL + T
- A dialog box appears, enable checkbox if your data set has headers.

- Press with left mouse button on OK.

### Explaining the formula in cell G6

Some of the cell references in the SUMIFS function are structured references pointing to a range in an Excel defined table. Structured references adjust automatically when data is added or removed to the table, the formula will instantly return the new running total.

Structured reference -> Table1[Amount]

The SUMIFS function adds numbers based on criteria and returns the total.

SUMIFS(*sum_range*,* criteria_range1*, *criteria1*, *[criteria_range2], [criteria2], *...)

#### Step 1 - First argument is sum_range

The sum_range argument is a structured reference: Table1[Amount]. This cell range contains the numbers to be added based on criteria.

#### Step 2 - Second and third argument

The first pair of arguments evaluates if cells in column **Client** equal value in cell G4.

Argument |
Cell reference |

criteria_range1 |
Table1[Client] |

criteria1 |
G4 |

#### Step 3 - Fourth and fifth argument

The second pair of arguments evaluates if cells in column **Date are **equal or are less than value in cell G3.

Argument |
Cell reference |

criteria_range2 |
Table1[Date] |

criteria2 |
"<="&G3 |

The less than and equal signs are concatenated to cell reference G3 using the ampersand character.

#### Step 4 - Sixth and seventh argument

The third pair of arguments evaluates if cells in column **Date are **equal or are larger than the value in cell G2.

Argument |
Cell reference |

criteria_range3 |
Table1[Date] |

criteria3 |
">="&G2 |

The larger than and equal signs are concatenated to cell reference G2 using the ampersand character.

## 3. Get the Excel file

## 4. Running totals based on criteria - Excel Table

This example shows how to calculate a running total using an Excel Table only based on a date range and a condition.

Excel 2007 and later versions let you add a total row below the Excel Table. Here is how to enable the total row:

- Select any cell in the Excel Table.
- A new tab on the ribbon appears named "Table Design", press with left mouse button on that tab to select it.
- Press with mouse on the "Total row" check box to enable it.

The total row is now visible.

### 4.1 How to filter an Excel Table

The Excel Table has small buttons containing an arrow next to the column header names. Press with mouse on the button next to "Date".

A popup menu appears, deselect all checkboxes except "January".

Press with left mouse button on the "OK" button.

Note, the button next to the column header name "Date" has changed, and the new icon tells you that a filter is present.

Press with left mouse button on the button next to the column header name "Client", and a popup menu appears.

Deselect all check boxes except "Client D", then press with left mouse button on the "OK" button.

### 4.2 How to clear an Excel Table filter

Press with left mouse button on the button next to the column header name you want to clear, a popup menu appears.

Press with left mouse button on "Clear Filter From "Date".

### Sum category

In this post, I will provide a formula to sum values in column (Qty) where a column (Date) meets two […]

The image above demonstrates a formula that calculates tiered values based on a tier table and returns a total. This […]

Table of Contents Sum unique numbers Get Excel *.xlsx file Sum unique distinct numbers Get Excel *.xlsx file Sum number […]

This article demonstrates how to find empty cells and populate them automatically with a formula that adds numbers above and […]

Katie asks: I have 57 sheets many of which are linked together by formulas, I need to get numbers from […]

Question: It's easy to sum a list by multiple criteria, you just use array formula a la: =SUM((column_plane=TRUE)*(column_countries="USA")*(column_producer="Boeing")*(column_to_sum)) But all […]

This article explains how to build an array formula that sums numerical ranges. Example, I want to know how to […]

The image above shows numbers in column B, some of these numbers are duplicates. The formula in D12 adds unique […]

To extract groups from cell range B3:B10 I use the following regular formula in cell B13.

The formula in cell C15 uses two dates two to filter and then sum values in column C, the SUMIFS […]

This article demonstrates a formula that calculates a running total. A running total is a sum that adds new numbers […]

The SUBTOTAL function lets you sum values in a cell range that have some rows hidden or filtered, the picture […]

I will in this article demonstrate different ways to sum values, the first method is so easy and fast it's […]

This article explains why your formula is not working properly, there are usually four different things that can go wrong. […]

## Functions in this article

More than 1300 Excel formulas

## Excel formula categories

## Excel categories

### 9 Responses to “Running totals based on criteria”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

Oscar,

Thank you so much!!!! Not only did this solve my issue, I have now learned a lot more about these functions to use on future projects.

Your site is a fabulous resource!!

Thank you again.

~Andrew

i think using only sumproduct formula too easy..

=SUMPRODUCT((B3:B25>=F3)*(B3:B25<=G3)*(C3:C25=H3)*(D3:D25))

mustafa,

The cell references have to be expanding as new records are added, in order to keep a running total.

Hello again Oscar,

I am playing with this some more, and I using the Microsoft Date and Time Picker (Excel 2010) to use for the two dates. I appear to have all the dates matching (dd/mm/yyyy) on both the PO list and my date range cells. However, the formula doesn't seem to be using the dates anymore?

Any thoughts?

Thanks.

~Andrew

Andrew Matheson,

Send me an excel file without sensitive information: Contact me

and I´ll se what I can do.

Looks like an easy pivot table solution to me.

David Hager,

As far as I know, pivot tables are not dynamically updated when new values are added.

The SUMPRODUCT function is easy to understand, it´s the dynamic ranges that make it look complicated.

Now I know: How to create a dynamic pivot table and refresh automatically in excel

For above example how to get date when for client d total exceeded $1200 through formula without helper cells.

Thanks