How to Use the BYROW Function in Excel to Apply Logic Across Rows

The Limitation of Traditional Array Formulas

Dynamic array formulas have revolutionized Microsoft Excel, allowing a single formula to spill results down an entire column. However, a major limitation arises when you try to apply complex logic—such as SUM, MAX, or TEXTJOIN—to an entire array. Instead of evaluating each row individually, Excel often collapses the entire 2D array into a single grand total.

To solve this, Microsoft introduced the BYROW function. BYROW forces Excel to evaluate a custom calculation row by row, returning an array of results that corresponds perfectly to the height of your original dataset.

Understanding the Syntax

The syntax for BYROW relies on the LAMBDA function to define the custom calculation:

=BYROW(array, LAMBDA(row_variable, calculation))

  • array: The 2D range of data you want to process (e.g., A2:C10).
  • LAMBDA: The helper function that performs the logic.
  • row_variable: A name you assign to represent the current row being processed (e.g., current_row or simply r).
  • calculation: The formula applied to that specific row.

Example 1: Calculating Maximum Sales per Employee

Imagine you have a table where column A contains employee names, and columns B, C, and D contain their sales figures for January, February, and March (range B2:D100). You want to find the highest single month of sales for each employee.

If you write =MAX(B2:D100), Excel will simply return the highest single value from the entire grid.

Instead, use BYROW:

=BYROW(B2:D100, LAMBDA(r, MAX(r)))

Here is what happens:

  1. BYROW looks at the first row of data (B2:D2) and assigns it to the variable r.
  2. The LAMBDA function calculates the MAX of r.
  3. BYROW moves to the next row (B3:D3) and repeats the process.
  4. The final result is a single vertical column that spills down, showing the maximum value for each individual employee.

Example 2: Counting Specific Values Across Rows

BYROW is exceptionally useful for survey data or attendance tracking. Suppose you have attendance records in columns B through F, marked as “Present” or “Absent”. You want to count how many days each student was absent.

=BYROW(B2:F50, LAMBDA(student_row, COUNTIF(student_row, "Absent")))

This single formula will evaluate all 49 students and return an array of 49 results. If you add a new student to row 51, you simply change the array reference to B2:F51, and the formula instantly scales.

Example 3: Combining Text Row by Row

Text manipulation is another area where BYROW shines. If you want to combine a user’s First Name (Column A), Middle Initial (Column B), and Last Name (Column C) into a single cell, ignoring blanks if they don’t have a middle initial, you can use TEXTJOIN inside BYROW:

=BYROW(A2:C100, LAMBDA(name_parts, TEXTJOIN(" ", TRUE, name_parts)))

Why Use BYROW Instead of Dragging Formulas?

While you could simply write =MAX(B2:D2) and drag it down 1,000 rows, BYROW offers significant advantages:

  • No Maintenance: If your dataset expands dynamically (e.g., using a spilled array like A2#), BYROW will automatically expand with it. Dragged formulas will not.
  • Smaller File Sizes: A single BYROW formula takes up less memory and calculates faster than 1,000 individual formulas.
  • Error Prevention: You never have to worry about accidentally deleting or altering a formula in the middle of a column.

Get the best tech tips delivered straight to your inbox.

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