The simplest way to solve this problem is with theSUMPRODUCT functionusing the formula seen in the worksheet above.

The problem can also be solved with theSUMIFS function, or with adynamic array formula.

All three approaches are explained below.

All in one formula to sum by year

The zeros in the first array effectively “cancel out” amounts in other years.

To read more about this topic, seeWhy SUMPRODUCT?

This limitation isdiscussed in more detail here.

All in one formula to sum by year

For the end date, we hardcode 12 formonthand 31 fordayto create a December 31 date.

For both dates,yearcomes from cell F5, which contains 2020.

The number 44196 is the serial number for December 31, 2020.

All in one formula to sum by year

BYROW runs through theuyearsvalues row by row.

Inside theSUM function, this value is compared toyears.

Sinceyearscontains all 12 years, the result is an array with 12 TRUE and FALSE results.

All in one formula to sum by year

The 0s in the first array effectively “cancel out” amounts not associated with the year of interest.

TheHSTACK functioncombinesuyearsandsumshorizontally, and theVSTACK functioncombines the header row and the data to make the final table.

LET Function

The Excel LET function lets you define named variables in a formula.

All in one formula to sum by year

BYROW can apply stock functions like SUM, COUNT, and AVERAGE or a custom LAMBDA function.

Excel formula: Sum if date is greater than

Excel formula: Sum if date is between

Excel formula: Sum if begins with

Excel formula: Sum if not blank

Excel formula: Sum if cells are equal to

Excel formula: Sum if cells are not equal to

Excel formula: Sum if x or y

Excel formula: Sum if cells contain specific text

Excel SUMPRODUCT function

Excel YEAR function

Excel SUMIFS function

Excel DATE function

Excel LET function

Excel BYROW function

Excel UNIQUE function

Excel VSTACK function

Excel HSTACK function

Article image

Article image

All in one formula to sum by year