ID EN
#Dynamic array

BYCOL

Excel Functions

Apply function to column

Syntax

EXCEL
=BYCOL(array, lambda)

Arguments

Parameter Description
array The array or array to process.
lambda The lambda function to apply to each column.

Return Value

One result per column

Details

The BYCOL function applies a function to each column in array and returns one result per column in a single array. For example, if BYCOL is given a range with 10 columns, it returns an array of 10 results, one per column. The calculation performed on each column can be a built-in function like SUM or COUNT, or a LAMBDA function that operates on column values using custom logic. BYCOL is especially useful in three situations: See below for specific examples. BYCOL takes two arguments: an array to process and a function to run on each column. The function can be written in two ways. The first way is as a long-form custom LAMBDA. This is the general form, and the one you'll see whenever the calculation needs custom logic: The second way is a short-form "eta lambda" syntax. Instead of wrapping

Examples

Basic usage

BYCOL takes two arguments: an array to process and a function to run on each column. The function can be written in two ways. The first way is as a lo

EXCEL
=BYCOL(array,LAMBDA(col,SUM(col)))
=BYCOL(array,LAMBDA(col,AVERAGE(IF(col<>0,col))))
=BYCOL(array,LAMBDA(col,MAX(col)-MIN(col)))
Basic usage

The second way is a short-form "eta lambda" syntax. Instead of wrapping the function in a LAMBDA, you provide just the function name. This works for s

EXCEL
=BYCOL(array,SUM) // sum each column
=BYCOL(array,MAX) // max of each column
=BYCOL(array,AVERAGE) // average of each column
=BYCOL(array,COUNTA) // count of non-empty values
Sum each column

In the worksheet below, the goal is to sum the test scores in each subject column of the range C5:H14. The formula in C16 is:

EXCEL
=BYCOL(C5:H14,SUM)
Sum each column

BYCOL processes all 6 subject columns at once and returns an array of 6 totals that spill into C16:H16. Notice we are using the short eta syntax above

EXCEL
=BYCOL(C5:H14,MAX) // max of each column
=BYCOL(C5:H14,MIN) // min of each column
=BYCOL(C5:H14,AVERAGE) // average of each column
Count values per column that meet a condition

BYCOL is useful when you want to count values per column that meet one or more specific conditions. This is where the eta syntax breaks down and the f

EXCEL
=BYCOL(C5:H14,LAMBDA(col,SUM(--(col>90))))
Average each column ignoring zeros

Zeros sometimes mean "no data" rather than "a real value of zero" (a student who missed an exam, a sensor that failed, a store that wasn't open, etc.)

EXCEL
=BYCOL(C5:H13,LAMBDA(col,AVERAGE(IF(col<>0,col))))

See Also

LAMBDA LET MAP SCAN REDUCE MAKEARRAY BYROW