formulastreak

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

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.

Q3 sales team · edit G2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultG2 = $37,300
ABCDEFG
1RepRegionJulAugSepTargetQ3
2Amara OseiNorth$12,400$13,100$11,800$36,000$37,300
3Ben FischerSouth$9,800$10,250$12,100$30,000$32,150
4Lina ChenEast$15,200$14,800$16,900$45,000$46,900
5Diego AlvarezWest$8,700$9,100$8,400$28,000$26,200
6Eva NovakNorth$11,200$12,600$13,900$36,000$37,700
7Farid HaddadSouth$13,300$12,900$14,100$39,000$40,300
8Grace KimEast$10,100$9,600$10,800$33,000$30,500
9Hugo MartinWest$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. 1. SUM: Adds up R.
    • range = `R`: the cells to add. Empty cells and text are skipped
  2. 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. 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 row
    • LAMBDA(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

ArgumentRequiredWhat it is
arrayYesThe block to go through, one row at a time, such as C2:E9.
lambdaYesA 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

  • #CALC!: The LAMBDA returns more than one value for a row, or there's no LAMBDA at all.
  • #VALUE!: The LAMBDA has the wrong number of parameters (BYROW needs exactly one).
  • #SPILL!: Cells below the formula aren't empty.
  • #NAME?: The file is open in Excel 2021 or older.

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.

Practise BYROW on a live sheet

Lesson 42, LAMBDA (Unit 12, LET and LAMBDA), has 7 graded exercises, checked instantly, with steps and hints when you're stuck. Pro