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.
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.
Explanation of this formula
> 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.
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
The Best Office Productivity Tools
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...
Supports Office/Excel 2007-2021 and 365 | Available in 44 Languages | Easy to Uninstall Completely
- 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, Edge and Firefox.