How to Get a Cumulative Sum in Excel If a Condition is Applied (6 Methods)

 

Method 1 – Using IF with Cell Reference for Excel Cumulative Sum with Condition

Steps:

  • In cell D5, enter the following formula:
=IF(C5<F5,C5,"")
  • Press Enter.

Using IF with Cell Reference for Excel Cumulative Sum with Condition

  • Enter the following formula in cell D6:
=IF(C6<$F$5,D5+C6,"")
  • Press Enter.
  • Drag the result using the Fill handle until the end of the table.

IF with cell reference for 2nd cell in result and dragging results

Formula Breakdown

In the first cell of the result, we used the IF formula, where the logic is the values of sales less than 5000.

Within the IF formula, the return for true is the same as the sales given otherwise blank.

For the second cell of the result, we put the same logic and false return value. The only change is the return for the true value, which will be a summation of the current sales value with the result of the previous cell.

Note: We can find the condition of 5000 in cell F5 and mention this in the formula as an absolute reference.

Read More: How to Calculate Running Total in One Cell in Excel


Method 2 – Using a Header Cell Reference for Excel Cumulative Sum with Condition

Steps:

  • Select the modified dataset.

Using Header Cell Reference for Excel Cumulative Sum with Condition

  • Select Table from the Insert tab.

Clicking Table from Insert tab

  • Check the range of the dataset and tick the My table has headers.
  • Click OK.

Checking table range and ticking headers

This will create a table with headers and an arrow sign for each, as shown below.

Excel table with arrow in headers

  • Choose a new column.
  • Enter the following formula in cell D5:
=SUM(Table1[[#Headers],[Sales]]:[@Sales])
  • Press Enter and drag the result until the end.

Result for header cell references

This was the result of the cumulative sum without any condition. It showed results for all the values.

  • If we apply the condition, it will show the cumulative sum for repetitive values only.
  • Enter the following formula in Cell E5:
=SUMIF(Table1[[#Headers],[Product]]:[@Product],[@Product],Table1[[#Headers],[Sales]]:[@Sales])
  • Press Enter and drag the result using the fill handle to the end of the table.

Header cell reference with condition

This will show the result of the cumulative sum for repetitive values only.

To see the result of the cumulative sum, you need to follow the steps:

  • Right-click the arrow with the Product header, and it will open a drop-down menu.
  • Select the product for which you want to see the result.
  • Click OK.

Filtering table for particular product ID

The result will look like this:

The result for particular repetitive product ID

Formula Breakdown

Creating the Excel table helped me directly click on headers and cells to refer to the cells without using cell references. It is called table references.

As the SUMIF function takes arguments of sum_range, which is the sales column in our case.

The other arguments include criteria range and criteria from the dataset’s product column.

The first SUMIF formula gave cumulative summation for all the data, while the second one was for the condition that only repetitive values will have the cumulative sum.

Read More: How to Calculate Horizontal Running Total in Excel


Method 3 – Using Nested IF and SUM for Excel Cumulative Sum with Condition

Steps:

  • Enter the SUM formula in Cell D5:
=SUM($C$5:C5)
  • Press Enter to get the result.
  • Drag the result to the end of the table.

Using Nested IF and SUM for Excel Cumulative Sum with Condition

  • If we use the IF formula to keep blank for the results of blank data, enter the formula in Cell E5:
=IF(C5="","",SUM($C$5:C5))
  • Press Enter and drag the result to where you want.

Final result for SUM and IF formula

Notice that there are no constant results in blank cells.

Formula Breakdown

The SUM formula uses cell references to give the result of summation.

It gives a constant value for blank cells.

Using the IF formula shows blank results for blank cells and cumulative sum for others.


Method 4 – Using SUM and INDEX for Excel Cumulative Sum If Condition Applied

Steps:

  • Select the dataset.

Using SUM and INDEX for Excel Cumulative Sum If Condition Applied

  • Choose Table from the Insert tab.

Using table from Insert tab for SUM and INDEX formula application

  • Check the table range and tick My table has headers option.
  • Click OK.

Checking table range and ticking headers for application of SUM and INDEX formula

The table will have headers with arrows.

Table with headers for application of SUM and INDEX formula

  • Enter the following formula in Cell D5:
=SUM(INDEX(Table2[[#Headers],[Sales]],1):Table2[@Sales])
  • Press Enter and drag the result till the end of the table.

Result of SUM and INDEX formula

The results will have repetitive values.

Observation of the result for SUM and INDEX formula

This does not consider and give results sequentially.

  • Right-click on the arrow beside the header of Product and select any of the repetitive products.
  • Click OK.

Filtering for repetitive cell in case of SUM and INDEX formula result

The result is the same.

Result of filtering using SUM and INDEX

Formula Breakdown

The INDEX formula uses row and column numbers to find a reference in a range.

After that, it uses the SUM formula to give the summation.


Method 5 – Using SUMIF/SUMIFS for Excel Cumulative Sum with Condition

5.1 Using SUMIF

Steps:

  • Enter the following formula in Cell D5:
=SUMIF(Table35[[#Headers],[Product]]:Table35[@Product],Table35[@Product],Table35[[#Headers],[Sales]]:Table35[@Sales])
  • Press Enter and drag the results below.

Using SUMIF for Excel Cumulative Sum with Condition

The results are only for the repetitive data.

Observation of the result of using SUMIF formula

5.2 Using SUMIFS

Steps:

  • Enter the following formula in cell E5:
=SUMIFS(Table35[[#Headers],[Sales]]:Table35[@Sales],Table35[[#Headers],[Product]]:Table35[@Product],Table35[@Product])
  • Press Enter and drag it using the fill handle.

Using SUMIFS for Excel Cumulative Sum with Condition

This gives results alike the SUMIF formula.


Method 6 – Using Pivot Table for Excel Cumulative Sum If Condition Applied

Steps:

  • Select the modified dataset.

Selecting the modified dataset for pivot table

  • Select Pivot Table from the Insert tab.

Selecting Pivot table from Insert tab

  • A new box will open where:
    • Check the table range.
    • Select Existing Worksheet.
    • Select a cell beside the dataset in the Location: section.
    • Click OK.

Checking range and selecting location of pivot table

This will open two boxes, one at the selected location and the other on the right side of the sheet. The boxes will look like this.

Pivot table box

Options for pivot table

  • Tick the Products and Sales. This will be shown in the Rows and Values section, as shown with arrows in the picture below.

Selecting options to create pivot table

  • Select the drop-down from the Sum of Sales and click Value Field Settings.

Selecting Value Field Settings

  • This will open a new box.
    • Enter Cumulative Sum in Custom Name: section.
    • Select Show Values As.
    • Choose Running Total from the Show values as a drop-down menu.
    • Select Product.
    • Click OK.

Creating cumulative sum column in pivot table

The result will be shown as follows.

Result of pivot table

Here, you can see that it adds up the repetitive values and shows only the cumulative sum for the unique product ID.


Download the Practice Workbook

You can download the workbook from the link below.


Related Articles


<< Go Back to Excel Running Total | Calculate in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Syeda Fahima Nazreen
Syeda Fahima Nazreen

SYEDA FAHIMA NAZREEN is an electrical & electronics engineer who loves exploring Excel and VBA programming. To her, programming is a time-saving tool for dealing with data, files, and the internet. She's skilled in Proteus, MATLAB, Multisim, AutoCAD, Jupiter Notebook, and MS Office, going beyond the basics. With a B.Sc in Electrical & Electronic Engineering from American International University, Bangladesh, she's shifted gears and now works as a content developer. In this role, she creates techy content exclusively... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo