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 =BYCOL(B2:D5,LAMBDA(c,SUM(c))) returns 157, 174, 179
Runs a LAMBDA on each column of an array and returns one result per column, as a single row.
Syntax
=BYCOL(, )
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 =BYCOL(B2:D5,LAMBDA(c,SUM(c))) returns 157, 174, 179
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.
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!.
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.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.
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.
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.
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.
B2:D5.LAMBDA(c,SUM(c)).Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
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 =BYCOL(B2:D5,LAMBDA(c,SUM(c))) returns 157, 174, 179
Example 2
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 =BYCOL(B2:D5,LAMBDA(c,MAX(c))) returns 56, 52, 60
Example 3
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 =BYCOL(B2:D5,LAMBDA(c,SUM(--(c>40)))) returns 1, 2, 3
Example 4
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 =FILTER(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))>170) returns Wk2, Wk3
Example 5
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 =VSTACK(B1:D1,BYCOL(B2:D5,LAMBDA(c,SUM(c)))) returns Wk1, Wk2, Wk3; 157, 174, 179
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.
#CALC!. Reduce each column with SUM, MAX, COUNT or similar.c>40 is a column of TRUE and FALSE values, so wrap it in SUM, AND or OR to get one answer.#SPILL! means something is in the cells beside the formula.SUM(B2:D5) copied across, or a Table total row, is simpler. Use BYCOL for calculations SUM can't express.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.
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.
Use `=BYCOL(B2:D5,LAMBDA(c,SUM(c)))`. Extend the range and the result gets another cell.
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.
No. It is available in Microsoft 365, Excel 2024 and later, and Excel for the web. Earlier versions return `#NAME?`.
Tracks take you from the basics to modelling, one graded exercise at a time.