Logical function

BYCOL function

Runs a LAMBDA on each column of a range and returns one result per column, for example a total or average for every month.

Available in Microsoft 365, Excel 2024, Excel for the web, Excel for Mac 2024

Excel 2024 and laterWorks in Google Sheets

Syntax

BYCOL(array, lambda(column))
ArgumentWhat it means
arrayRequiredThe range or array whose columns you want to process.
lambdaRequiredA LAMBDA with exactly one parameter. BYCOL passes each column to it in turn; it must return a single value.

Returns: A one-row array with one value per column, which spills to the right.

How BYCOL works

BYCOL lets you write one formula that summarises every column of a table. Instead of typing =AVERAGE(B2:B5) under January, copying it under February and March, and fixing it whenever columns are added, you write a single formula and it spills a row of answers — one per column.

You describe what should happen to one column with a LAMBDA, such as LAMBDA(col, AVERAGE(col)). BYCOL hands each column to that LAMBDA as the variable col and collects the results side by side. The LAMBDA must return one value per column; if it returns several values you get #CALC!. Its sister function BYROW does the same across rows.

Examples

1Average monthly sales across stores

B6fx=BYCOL(B2:D5, LAMBDA(col, AVERAGE(col)))
ABCD
1StoreJanFebMar
2Athens120013501100
3Berlin98010101250
4Cairo150014201610
5Dublin760890940
611101167.51225

Each month column is passed to AVERAGE. January averages (1200+980+1500+760)/4 = 1110, February 1167.5 and March 1225. The results spill from B6 to D6, right under their months.

2Best store result per month

B7fx=BYCOL(B2:D5, LAMBDA(col, MAX(col)))
ABCD
1StoreJanFebMar
2Athens120013501100
3Berlin98010101250
4Cairo150014201610
5Dublin760890940
6
7150014201610

The same pattern with MAX gives the highest figure in each month: 1500, 1420 and 1610 (Cairo every time).

3How many stores reached 1,000 each month

B8fx=BYCOL(B2:D5, LAMBDA(col, COUNTIF(col, ">=1000")))
ABCD
1StoreJanFebMar
2Athens120013501100
3Berlin98010101250
4Cairo150014201610
5Dublin760890940
6
7
8233

COUNTIF counts the values of at least 1,000 in each column: 2 stores in January, 3 in February and 3 in March.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#CALC!The LAMBDA returns more than one value for a column (for example LAMBDA(c, c*2)).Make sure the LAMBDA reduces the column to a single value, or use MAP for element-by-element results.
#VALUE!The LAMBDA has no parameter or more than one.Give it exactly one parameter: LAMBDA(col, ...).
#SPILL!Cells to the right of the formula are not empty.Clear the cells the result needs.

Tips

  • In current Microsoft 365 builds you can pass a function name directly: =BYCOL(B2:D5, SUM) is short for LAMBDA(c, SUM(c)).
  • Point BYCOL at a whole Excel Table column set (e.g. Sales[[Jan]:[Mar]]) and the results grow automatically when rows are added.

Google Sheets

BYCOL also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.