Going Stellar

Home/Google Sheets reference

Google Sheets function · Array

BYCOL in Google Sheets: syntax and examples

BYCOL hands each column of a range to a LAMBDA and collects the results in a single row. It replaces a row of copied formulas with one formula, for column totals, maximums, averages or labels.

Syntax

BYCOL(array_or_range, LAMBDA)

Arguments

ArgumentTypeRequiredWhat it does
array_or_rangerangeyesThe array or range to split into columns. Each column is passed to the LAMBDA once.
LAMBDAlambdayesA LAMBDA with exactly one name. It receives one column and must return one value.

Examples

The examples use this table, starting in A1:

NameQ1Q2Q3
Ana102030
Bob51525
Cris789
=BYCOL(B2:D4, LAMBDA(c, SUM(c)))

Result:

224364

Column totals: one number per column, returned as a row.

Run in a Google Sheet (English US locale) on .

=BYCOL(B2:D4, LAMBDA(c, MAX(c)))

Result:

102030

The best score in each quarter.

Run in a Google Sheet (English US locale) on .

=BYCOL(B2:D4, LAMBDA(c, AVERAGE(c)))

Result:

7.33333333314.3333333321.33333333

Average per column.

Run in a Google Sheet (English US locale) on .

=BYCOL(B2:D4, LAMBDA(c, MAX(c) - MIN(c)))

Result:

51221

The spread in each quarter: highest minus lowest.

Run in a Google Sheet (English US locale) on .

=BYCOL(B2:D4, LAMBDA(c, IF(SUM(c)>30, "high", "low")))

Result:

lowhighhigh

A label per column, based on its total.

Run in a Google Sheet (English US locale) on .

Common errors

  • The LAMBDA takes exactly one name, the column. A LAMBDA with two names, as in LAMBDA(c, r, SUM(c)), returns #N/A.
  • The second argument must be a LAMBDA. A bare function name such as SUM returns #N/A.
  • A text column is not skipped. In A2:D4 the Name column gives 0 for SUM, so start the range at the numbers, as in B2:D4.
  • The result is always one row with one cell per column, however many rows the range has.

Compared with Excel

Same syntax in Excel.

Sources

  1. BYCOL (Docs Editors Help)

Markdown version · All functions