Note: The other languages of the website are Google-translated. Back to English
English English

Get subtotal by invoice number in Excel

This tutorial explains a formula based on the COUNTIF and SUMIF functions to get subtotal by invoice number in Excel.


How to get subtotal by invoice number in Excel?

Take the above table as an example, to get subtotal by the first occurrence of the invoice number, you can apply the below formula.

Generic Formulas

=IF(COUNTIF(range,criteria)=1,SUMIF(range,criteria,sumrange,"")

Arguments

Range: Represents the expanding range of the invoice number that you want to get subtotal based on;
Criteria: Represents the first invoice number. It can be a text string wrapped in double quotation marks, or a cell that references the invoice number;
Sumrange: Represents the range that you will sum.

How to use this formula?

1. Firstly, select a blank cell to output the result. In this case, I select a blank cell (E5) in the same row as the first invoice number.

2. Copy or enter the below formula into the selected cell and press Enter key. Select the result cell, drag its AutoFill Handle down to get the subtotals for other invoice numbers.

=IF(COUNTIF($B$3:B3,B3)=1,SUMIF($B:$B,B3,$D:$D),"")

Explanation of this formula

=IF(COUNTIF($B$3:B3,B3)=1,SUMIF($B:$B,B3,$D:$D),"")

> COUNTIF($B$3:B3,B3)=1: Here the COUNTIF function is used with an expanding range to check if the current row is the first occurrence of a given invoice number. If it is, it returns TRUE, otherwise it returns FALSE.
Here, in this case, ABS1101 in cell B3 is the first occurrence of the invoice number of ABS1101, then it gets the result of COUNTIF(1=1): TRUE.
> SUMIF($B:$B,B3,$D:$D)The SUMIF function performs a total sum in the Subtotal column based on the invoice number. Here the SUMIF function returns the result of 3289.
> IF(TRUE,3289,"")If the result obtained by the COUNTIF function is TRUE, the SUMIF function will return the result of this calculation, otherwise, it will return a null value. The final result here is 3289.

Related functions

Excel IF function
The Excel IF function performs a simple logical test which depending on the comparison result, and it returns one value if a result is TRUE, or another value if result is FALSE.

Excel COUNTIF function
The Excel IF function is a statistical function in Excel which is used to count the number of cells that meet a criterion.

Excel SUMIF function
The Excel SUMIF function can help to sum cells based on one criterion


Related formulas

3D sum or sumif across multiple worksheets
This tutorial talks about how to sum the same range of cells across multiple consecutive or discontiguous worksheets in Excel.

Calculate running total
This tutorial explains a simple formula to help calculating running total in Excel.

Subtotal by colors
This step-by-step guide helps you perform subtotal by color with the SUMIF function.

Two-way summary counting
In this tutorial, we will discuss how to use the COUNTIFS function to create two-way summary count in Excel.


The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

  • Designed for 1500 work scenarios, helps you solve 80% Excel problems.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.
Ribbon of Excel (with Kutools for Excel installed)

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.
Screen Shot of Excel (with Office Tab installed)
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations