How to Use the BYCOL Function in Google Sheets | Aggregate and Calculate Column by Column
What Is the BYCOL Function?
The BYCOL function splits a specified table (cell range) column by column, applies a calculation defined by a LAMBDA function (such as sum, average, or count) to each column, and returns the results as a single horizontal row array. It is ideal for creating a “Total” row at the bottom of a table using just one formula.
Syntax
=BYCOL(array, LAMBDA(column, formula_expression))
- array: The cell range or array to calculate column by column.
- LAMBDA(column, formula_expression): The calculation applied to each column. The
columnparameter receives one column’s range at a time.
Example
Here is an example of calculating total monthly sales for each month (column by column) from the data in B2:D4 using a single formula in cell B5.
| Row | Column A (Branch) | Column B (Apr) | Column C (May) | Column D (Jun) |
|---|---|---|---|---|
| 1 | Branch | Apr | May | Jun |
| 2 | Tokyo | 100 | 120 | 110 |
| 3 | Osaka | 80 | 90 | 95 |
| 4 | Nagoya | 60 | 70 | 75 |
| 5 | Total | =BYCOL(B2:D4, LAMBDA(c, SUM(c))) |
(Auto-spilled: 280) | (Auto-spilled: 280) |
Note: 240 is output in cell B5, and 280 and 280 spill automatically into C5 and D5.
Common Errors and Notes
#VALUE!Error (Not Returning a Single Value): TheLAMBDAcalculation must return exactly one value per column. Returning a multi-row array causes a#VALUE!error.#REF!Error (Existing Values to the Right): Results spill horizontally to the right from the formula cell. A#REF!error occurs if any cell to the right already contains a value or formula.- Watch Out for Empty Columns: If a column contains no numbers, functions like
AVERAGEorMINmay return#DIV/0!or other errors. Wrapping the calculation inIFERRORhelps keep your summary row clean.
Frequently Asked Questions
Q. What is the difference between BYCOL and BYROW?
A. BYROW calculates row by row (horizontally) and returns results in a single vertical column, whereas BYCOL calculates column by column (vertically) and returns results in a single horizontal row.
Q. How do I find the average of each column at once using BYCOL?
A. Write =BYCOL(B2:E10, LAMBDA(col, AVERAGE(col))). The average of each column from B to E is output side by side in a single horizontal row.