Explanation
This formula uses COUNTIF with an expanding range to first check if the current row is the first occurrence of a given invoice number:
COUNTIF($B$5:B5,B5)=1
This expression only returns TRUE when this is the first occurrence of a given invoice number. If so, a SUMIF calculation is run:
SUMIF($B:$B,B5,$D:$D)
Here, SUMIF generates a total sum by invoice number, using the amounts in column D. If the count is not 1, the formula simply returns an empty string ("")
Related formulas
Sum if multiple criteria
Subtotal invoices by age
Subtotal by color
Related functions
SUMIF Function
The Excel SUMIF function returns the sum of cells that meet a single condition. Criteria can be applied to dates, numbers, and text. The SUMIF function supports logical operators (>,<,<>,=) and wildcards (*,?) for partial matching....
COUNTIF Function
The Excel COUNTIF function returns the count of cells in a range that meet a single condition. The generic syntax is COUNTIF(range, criteria), where "range" contains the cells to count, and "criteria" is a condition that must be true for a cell to be counted. COUNTIF can be used to count cells...