How to Use the BYROW and BYCOL Functions in Google Sheets to Process Arrays

Applying standard aggregation formulas across large tables in Google Sheets historically required dragging calculation formulas down hundreds of rows or writing complicated ARRAYFORMULA hacks with MMULT. Functions like SUM or AVERAGE naturally collapse an entire multi-cell range into a single aggregate value rather than returning a neat column of row-by-row results.

Google Sheets resolved this limitation by introducing the BYROW and BYCOL helper functions powered by LAMBDA. These functions allow spreadsheet authors to iterate over each row or column of an array individually and return a dynamic spilled array of answers automatically. In this guide, we explore syntax, practical mathematical calculations, text concatenation examples, and performance advantages.

Understanding BYROW and BYCOL Mechanics

Both functions take an input matrix, slice it into vector segments (individual rows or individual columns), and pass each segment into a custom LAMBDA calculation:

Function Iteration Direction Lambda Input Parameter Output Dimension
BYROW(array, lambda) Horizontal row slices, moving downwards Single row vector (e.g., r representing A2:D2) Vertical column of answers (one cell per row)
BYCOL(array, lambda) Vertical column slices, moving sideways Single column vector (e.g., c representing A2:A100) Horizontal row of answers (one cell per column)

When engineering advanced calculation models, combining these array iterators with the LET function in Google Sheets keeps your nested formulas legible and performant.

Syntax and Argument Structure

The syntax for both functions is consistent and concise:

=BYROW(array, LAMBDA(row, calculation))
=BYCOL(array, LAMBDA(column, calculation))
  • array: The two-dimensional range of cells or computed array you wish to evaluate (e.g., B2:F50).
  • LAMBDA: The container that accepts a variable name representing each row/column and returns the evaluated expression.

Calculating Row-by-Row Totals Using BYROW

Suppose you have quarterly sales figures across columns B2:E20 and want total sales per employee in column F. Rather than dragging =SUM(B2:E2) down nineteen rows, enter this single formula in cell F2:

=BYROW(B2:E20, LAMBDA(r, SUM(r)))

Google Sheets evaluates each row independently and spills twenty total values down column F. If you append new rows or edit quarterly numbers, totals recalculate instantaneously.

Calculating Column Averages Using BYCOL

To compute the average grade or metric for each column across a wide dataset spanning C2:Z100, enter this formula in cell C101:

=BYCOL(C2:Z100, LAMBDA(c, AVERAGE(c)))

The output expands horizontally across row 101, delivering an individual column mean for every subject without requiring duplicate formulas.

Advanced Transformations: Conditional Counts and Text Joins

The real power of BYROW and BYCOL emerges when handling non-trivial logic that standard array formulas cannot process natively:

1. Counting Occurrences Greater Than a Threshold per Row

To count how many days an employee exceeded 8 hours worked in range B2:H20:

=BYROW(B2:H20, LAMBDA(r, COUNTIF(r, ">8")))

2. Concatenating First and Last Names with Delimiters

To join first names (column A) and surnames (column B) with a tidy space across an entire roster:

=BYROW(A2:B100, LAMBDA(r, TEXTJOIN(" ", TRUE, r)))

If you want to visualize these generated summaries with miniature graphic trends, pairing row totals with in-cell Sparkline charts in Google Sheets produces elegant executive dashboards.

Frequently Asked Questions

Why does BYROW return a #VALUE! error?

A #VALUE! error occurs if your LAMBDA expression returns an array of multiple values rather than a single scalar value for each row. Ensure the formula inside your Lambda (such as SUM, MAX, or TEXTJOIN) aggregates each slice down to one result.

Can I nest FILTER inside a BYROW formula?

Yes. You can filter rows inside the Lambda calculation: =BYROW(B2:E50, LAMBDA(r, AVERAGE(FILTER(r, r > 0)))) will average only positive values in each row.

Do BYROW and BYCOL work if the source range contains empty rows?

Yes. The functions process empty rows based on the mathematical properties of your chosen aggregator (for example, SUM treats empty cells as 0, while COUNT ignores them).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.