where data is the named range B5:G14, and headers is the named range B4:G4. The formula sums columns where headers begin with “A” and returns 201. Note: In the current version of Excel you can also use the FILTER function, as explained below. To apply a filter by matching column headers – columns with headers that begin with “A” – we use the LEFT function like this: This expression returns TRUE if a column header begins with “a”, and FALSE if not. The result is an array: You can see that values 1,2, and 5 correspond to columns that begin with “a”. Inside SUMPRODUCT, this array is multiplied by “data”. Due to broadcasting, the result is a two-dimensional array like this: If we visualize this array in a table, it’s easy to see that only values in columns that begin with “a” have survived the operation, all other columns are zero. In other words, the filter keeps values of interest and “cancels out” the rest: With only a single array to process, SUMPRODUCT returns the sum of all values, 201.
Sum by exact match
The example above shows how to sum columns that begin with one or more specific characters. To sum column based on an exact match, you can use a simpler formula like this:
FILTER function
In the latest version of Excel, you can solve this problem more directly with the FILTER function like this: In this formula, we use the same logic we used in the SUMPRODUCT function to select only data in columns that begin with the letter “A”: The expression above returns an array of TRUE and FALSE values like this: Notice that the TRUE values correspond to column headers that begin with “A”. The FILTER function uses this array to select columns in the named range data. Because this array is horizontal, FILTER automatically filters on columns. The FILTER function returns the 3 columns in data with headers that begin with “A” to the SUM function, which returns a final result of 201.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.