Dynamic arrays function
BYROW function in Google Sheets and Excel
BYROW passes each row of a range to a LAMBDA and spills one result per row, such as a total or maximum for every row.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
BYROW(array, lambda(row))Arguments in [brackets] are optional. Google Sheets writes it BYROW(array_or_range, LAMBDA).
Example
=BYROW(C2:E9,LAMBDA(r,SUM(r))) reads: Go through the sales block C2:E9 one row at a time, call each row r, and return SUM(r): each rep's July-to-September total, spilled down.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Rep | Region | Jul | Aug | Sep | Target | Q3 |
| 2 | Amara Osei | North | $12,400 | $13,100 | $11,800 | $36,000 | $37,300 |
| 3 | Ben Fischer | South | $9,800 | $10,250 | $12,100 | $30,000 | $32,150 |
| 4 | Lina Chen | East | $15,200 | $14,800 | $16,900 | $45,000 | $46,900 |
| 5 | Diego Alvarez | West | $8,700 | $9,100 | $8,400 | $28,000 | $26,200 |
| 6 | Eva Novak | North | $11,200 | $12,600 | $13,900 | $36,000 | $37,700 |
| 7 | Farid Haddad | South | $13,300 | $12,900 | $14,100 | $39,000 | $40,300 |
| 8 | Grace Kim | East | $10,100 | $9,600 | $10,800 | $33,000 | $30,500 |
| 9 | Hugo Martin | West | $14,500 | $15,800 | $15,100 | $42,000 | $45,400 |
G2 shows $37,300: Amara's three months added; the column spills down to Hugo's $45,400.
How the spreadsheet calculates it
Runs the result of LAMBDA (step 2) on each row of C2:E9, one result per row.
- 1. SUM: Adds up
R.range=`R`: the cells to add. Empty cells and text are skipped
- 2. LAMBDA: Describes your own function: given
R, it works out the result of step 1.parameter=`R`: a name for each input and `p`calculation=the result of step 1: what to work out with them
- 3. BYROW: Runs the result of step 2 on each row of
C2:E9, one result per row.range=`C2:E9`: the block to go through row by rowLAMBDA(row, calculation)=the result of step 2: what to work out for each row
More BYROW examples
=BYROW(C2:E9,LAMBDA(r,MAX(r)))Each rep's best month.=BYROW(C2:E9,LAMBDA(r,AVERAGE(r)))Each rep's average monthly sales.=BYROW(C2:E9,LAMBDA(r,AND(r>=10000)))TRUE where every month reached 10,000.=BYROW(C2:E9,LAMBDA(r,SUM(r)))-F2:F9Each rep's quarter total minus their target.
Paste any of these into the formula explainer to see it step by step.
Tips
- Start with SUM to check BYROW is set up right, then swap in the calculation you really need.
- Keep the range to the numbers only; put labels outside it.
- Use LET inside the LAMBDA when the calculation for a row has several steps.
- Combine with FILTER or SORTBY when you want rows picked or ordered by their row result.
What BYROW is used for
Row totals and averages in a block of monthly figures, flagging rows where every (or any) value passes a test, and finding each person's best month without a helper column per row.
Arguments
| Argument | Required | What it is |
|---|---|---|
| array | Yes | The block to go through, one row at a time, such as C2:E9. |
| lambda | Yes | A LAMBDA with one parameter for the row, returning a single value: LAMBDA(r, SUM(r)).Watch out: A LAMBDA that returns several values per row gives #CALC!. |
Common mistakes
Using MAP when you need the whole row: MAP passes single cells.
Returning more than one value per row, for example
LAMBDA(r, r*2): Microsoft's page says anything but a single value gives #CALC!.Including the header row or a name column in the range, so the first result is text or an error.
Expecting columns: BYROW goes across rows; for one result per column use BYCOL.
In Google Sheets
Google Sheets has BYROW, written BYROW(array_or_range, LAMBDA): the same two arguments in the same order.
Errors you may see with BYROW
Questions
How do I get a total for every row with one formula?
Use BYROW(C2:E9, LAMBDA(r, SUM(r))), as in the example. Swap SUM for MAX, AVERAGE or COUNT to get that per row instead.
BYROW or MMULT for row totals?
BYROW reads like what it does and works with any function that summarises a row. Older tricks with matrix maths work too but are much harder to read and change.
Can BYROW test a whole row?
Yes: BYROW(C2:E9, LAMBDA(r, AND(r>=10000))) returns TRUE for reps who sold at least 10,000 in every month. Anything that turns a row into one value works.
Sources
Official documentation the facts on this page were checked against.