Skip to content

BYCOL

Runs a LAMBDA on each column of an array and returns one result per column, as a single row.

Syntax

=BYCOL(, )

LAMBDA and LET

Excel for Microsoft 365, Excel 2024 and later, and Excel for the web. Not available in Excel 2021 or earlier.

Try it

Edit the formula in B7 or change the inputs. The sheet recalculates as you type.

B7
A
B
C
D
E
F
G
H
1
Branch
Wk1
Wk2
Wk3
2
North
40
52
47
3
South
33
38
41
4
East
56
49
60
5
West
28
35
31
6
7
157
174
179
8

B7 =BYCOL(B2:D5,LAMBDA(c,SUM(c))) returns 157, 174, 179

How BYCOL works

BYCOL takes an array column by column, runs a calculation on each whole column and returns the answers across a row. It is the way to get a total, a maximum or a test for every column with one formula, and it is the column version of BYROW.

The arguments

  • array is the block to process. Each column of it is handed to the LAMBDA in turn.
  • lambda has one parameter, which holds one entire column. Inside the LAMBDA you can use it like a range: SUM(c), MAX(c), AVERAGE(c), COUNT(c).

=BYCOL(B2:D5,LAMBDA(c,SUM(c))) returns the total for each of the three weeks as three cells spilled across a row. The LAMBDA must return one value for each column. If it returns a list, BYCOL returns #CALC!.

Why use BYCOL

Totals under each column are usually a SUM that you copy right. BYCOL replaces that with one formula that covers every column, and keeps working when you widen the range. It matters most when the calculation isn't a simple SUM:

  • =BYCOL(B2:D5,LAMBDA(c,MAX(c))) returns the best result in each week.
  • =BYCOL(B2:D5,LAMBDA(c,SUM(--(c>40)))) counts the branches above 40 in each week. The double minus turns TRUE and FALSE into 1 and 0.

Picking columns by a condition

FILTER can work on columns as well as rows, if its test has one TRUE or FALSE for each column. BYCOL produces that test:

=FILTER(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))>170)

This returns the headings of the weeks whose total is over 170. The same test with B1:D5 as the array returns whole columns, header included.

Adding the results as a total row

Place the totals under the data with VSTACK. =VSTACK(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))) returns the header row with the totals right below it, as a labelled summary.

BYCOL, BYROW and MAP

BYROW gives one answer for each row, BYCOL one for each column, and MAP one for each cell. All of them need a LAMBDA that returns a single value. See LAMBDA for writing one.

Notes

The result is one row with one cell per column of the input, and it spills to the right. #SPILL! means the cells to its right aren't empty. Keep text columns out of the range or the LAMBDA has to cope with them: SUM ignores text, but AVERAGE of a text-only column returns #DIV/0!.

BYCOL needs Microsoft 365, Excel 2024 or later, or Excel for the web.

Arguments

array
The range or array whose columns you want to process, such as B2:D5.
lambda
A LAMBDA with one parameter. Each call receives a whole column of the array and must return a single value, such as LAMBDA(c,SUM(c)).

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Total of each column

B7 =BYCOL(B2:D5,LAMBDA(c,SUM(c)))

Result: 157, 174, 179

The LAMBDA receives one week at a time. Wk1: 40 + 33 + 56 + 28 = 157.

B7
A
B
C
D
E
F
G
H
1
Branch
Wk1
Wk2
Wk3
2
North
40
52
47
3
South
33
38
41
4
East
56
49
60
5
West
28
35
31
6
7
157
174
179
8

B7 =BYCOL(B2:D5,LAMBDA(c,SUM(c))) returns 157, 174, 179

Example 2

The best branch result in each week

B7 =BYCOL(B2:D5,LAMBDA(c,MAX(c)))

Result: 56, 52, 60

MAX looks at one whole column. East tops weeks 1 and 3, and North tops week 2.

B7
A
B
C
D
E
F
G
H
1
Branch
Wk1
Wk2
Wk3
2
North
40
52
47
3
South
33
38
41
4
East
56
49
60
5
West
28
35
31
6
7
56
52
60
8

B7 =BYCOL(B2:D5,LAMBDA(c,MAX(c))) returns 56, 52, 60

Example 3

Count the branches above 40 in each week

B7 =BYCOL(B2:D5,LAMBDA(c,SUM(--(c>40))))

Result: 1, 2, 3

c>40 is TRUE or FALSE for each branch. The double minus turns those into 1 and 0, and SUM adds them. In week 1 only East is above 40.

B7
A
B
C
D
E
F
G
H
1
Branch
Wk1
Wk2
Wk3
2
North
40
52
47
3
South
33
38
41
4
East
56
49
60
5
West
28
35
31
6
7
1
2
3
8

B7 =BYCOL(B2:D5,LAMBDA(c,SUM(--(c>40)))) returns 1, 2, 3

Example 4

Show the weeks whose total is over 170

B7 =FILTER(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))>170)

Result: Wk2, Wk3

BYCOL gives FILTER one total per column. Wk1 totals 157, so only Wk2 (174) and Wk3 (179) pass.

B7
A
B
C
D
E
F
G
H
1
Branch
Wk1
Wk2
Wk3
2
North
40
52
47
3
South
33
38
41
4
East
56
49
60
5
West
28
35
31
6
7
Wk2
Wk3
8

B7 =FILTER(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))>170) returns Wk2, Wk3

Example 5

Headings with their totals underneath

B7 =VSTACK(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c))))

Result: Wk1, Wk2, Wk3; 157, 174, 179

VSTACK puts the heading row above the row of totals.

B7
A
B
C
D
E
F
G
H
1
Branch
Wk1
Wk2
Wk3
2
North
40
52
47
3
South
33
38
41
4
East
56
49
60
5
West
28
35
31
6
7
Wk1
Wk2
Wk3
8
157
174
179

B7 =VSTACK(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))) returns Wk1, Wk2, Wk3; 157, 174, 179

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B7, return the highest number of tickets closed on each day (the maximum of each column from B to D), using BYCOL.

Answer in B7.

B7
A
B
C
D
E
F
G
H
1
Team
Mon
Tue
Wed
2
Alpha
14
20
18
3
Bravo
22
15
25
4
Delta
9
12
16
5
Echo
30
28
21
6
7
8
9
10
11
12

Common mistakes

  • The LAMBDA must return one value per column. Returning a column or list gives #CALC!. Reduce each column with SUM, MAX, COUNT or similar.
  • The parameter holds the whole column. c>40 is a column of TRUE and FALSE values, so wrap it in SUM, AND or OR to get one answer.
  • Start the range below the header row. If the headings are in the range, the LAMBDA receives text along with the numbers.
  • A row of results spills to the right. #SPILL! means something is in the cells beside the formula.
  • For plain column totals, SUM(B2:D5) copied across, or a Table total row, is simpler. Use BYCOL for calculations SUM can't express.

Questions people ask

What does BYCOL do in Excel?

It runs a LAMBDA on each column of an array and returns one result per column, across a row. For example, `=BYCOL(B2:D5,LAMBDA(c,SUM(c)))` totals every column with one formula.

What is the difference between BYCOL and BYROW?

BYCOL passes one column at a time and returns a row of results. BYROW passes one row at a time and returns a column of results.

How do I add up every column without copying the formula across?

Use `=BYCOL(B2:D5,LAMBDA(c,SUM(c)))`. Extend the range and the result gets another cell.

How do I show only the columns that meet a condition?

Combine FILTER and BYCOL: `=FILTER(B1:D5,BYCOL(B2:D5,LAMBDA(c,SUM(c)))>170)` returns the columns, headings included, whose total is above 170.

Does BYCOL work in Excel 2021?

No. It is available in Microsoft 365, Excel 2024 and later, and Excel for the web. Earlier versions return `#NAME?`.

Learn BYCOL in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.