BYROW
Short answer
One formula, a result per row
BYROW(array, lambda(row))
- Category
- Dynamic Arrays & Modern Excel
- Excel version
- 2024+
- Also searched as
- bycol, row totals one formula, spill row totals, sum each row, total each column, row level check excel, sum by row dynamic array
What it returns
BYROW hands each row of an array to a LAMBDA, one row at a time, and returns a column with one result per row. Feed it a 30-line by 12-month P&L grid and a LAMBDA that sums its input, and you get 30 row totals, spilled down from one cell.
BYCOL is the same function turned sideways. It hands each column to the LAMBDA and returns a row with one result per column. The same grid gives 12 monthly totals.
The LAMBDA has to return a single value for each row or column. BYROW cannot return a grid of grids, so a LAMBDA that returns an array gives #CALC!.
Video: the BYROW Short on YouTube shows the core pattern in under a minute.
Arguments that matter
| Argument | Required | What it does |
|---|---|---|
array | Yes | The grid to process. A range, a Table’s data columns, or a spilled array. |
lambda | Yes | A LAMBDA with one parameter. That parameter receives one row (BYROW) or one column (BYCOL). It must return one value. |
The parameter name is yours to choose. line or month reads better in review than x. Avoid single letters that look like references.
In current Microsoft 365 you can pass a function name in place of a full LAMBDA: =BYROW(D12:O40, SUM). It is shorter and reads well. If the file has to work in a version that rejects it, write the LAMBDA out in full.
In a financial model
Row totals are the obvious use, and the stronger case for BYROW over a filled-down SUM is integrity.
A column of filled-down totals is one formula per line. Any one of them can be typed over with a number, and the grid looks the same. A spilled total is one formula. Type a value into the middle of it and the whole spill collapses to #SPILL!. The override is impossible to miss, which is the point.
It also follows the data. Point BYROW at a spilled grid, such as a GROUPBY or FILTER output, and the totals grow and shrink with it. A filled-down column has to be extended by hand every time a line is added.
The second use is row-level checks. A consolidation tab with one row per entity and columns for each elimination should net to zero across every row. BYROW returns a pass or fail per entity in one formula, and a single COUNTIF of the failures goes in the check row, per build a check row and make it loud.
BYCOL handles the monthly version: does the balance sheet balance in every period? One formula across the top, read by the master check.
Worked example
An income statement grid on tab IS, line items in B12:B40, months across D12:O40. Every cell is a SUMIFS against the ledger.
Row totals in P12:
=BYROW(IS!D12:O40, LAMBDA(line, SUM(line)))
One formula, 29 results. Monthly totals under the grid, in D42:
=BYCOL(IS!D12:O40, LAMBDA(month, SUM(month)))
A row check on tab Consol, with entities down B8:B20 and the reported figure, local adjustments and eliminations in D8:F20. Each row should net to zero once eliminations are signed correctly:
=BYROW(Consol!D8:F20, LAMBDA(entity, ABS(SUM(entity))<0.005))
| Entity | Reported | Adjustments | Eliminations | Check |
|---|---|---|---|---|
| UK Ltd | 1,250 | (50) | (1,200) | TRUE |
| US Inc | 3,400 | 0 | (3,400) | TRUE |
| DE GmbH | 900 | 25 | (900) | FALSE |
The check row then reads =COUNTIF(Consol!G8#, FALSE), expected zero. The # reference picks up the whole spill, however many entities there are.
Old way vs new way
Filled down from row 12 to row 40:
=SUM(D12:O12)
One cell, spilled:
=BYROW(D12:O40, LAMBDA(line, SUM(line)))
The filled-down version is 29 formulas, any of which can be overwritten in silence. The spilled version is one formula, and an overwrite breaks it loudly.
Where it breaks
BYROW returns #CALC!. The LAMBDA returns more than one value per row. LAMBDA(line, line*1.1) returns twelve numbers for a twelve-month row, and BYROW cannot hold them. Fix: wrap the result in something that returns one value, such as SUM, MAX or AND, or use MAP if you want a result per cell.
The total column shows #SPILL!. Something sits in the cells the result needs: a stray number, an old SUM, a hard-coded override. Fix: select the anchor cell, follow the dashed border to the blocking cell and clear it. If someone typed over a total on purpose, that conversation needs to happen in the model’s change log.
#SPILL! inside a Table. Tables do not accept spilled results. Fix: put BYROW in a plain range next to the Table, or use a calculated column with a normal SUM if the totals must live in the Table.
Totals stop short when lines are added. The array argument is a fixed range, and new rows were inserted below it. Fix: point BYROW at the spill of the grid itself (D12#), at a Table, or at a trimmed range with TRIMRANGE.
Every cell shows #NAME?. BYROW and BYCOL need Excel 2024 or Microsoft 365. Excel 2021 does not have them. Fix: for files that travel to older versions, fall back to filled-down SUMs.
The short form BYROW(grid, SUM) returns an error. Passing a bare function name needs a recent Microsoft 365 build. Fix: write the full LAMBDA(line, SUM(line)), which works everywhere BYROW does.
Related functions
- LAMBDA. Every BYROW takes one. A named LAMBDA can go straight in:
=BYROW(grid, RowCheck). - MAP. For one result per cell rather than per row. Reach for it when the logic applies to each value on its own.
- SUMIFS. Builds the grid that BYROW totals. Use SUMIFS for totals straight from the ledger and BYROW for totals of what is already on the tab.
- TAKE. Pair it with BYROW for a trailing twelve-month total per line: hand each row’s last twelve columns to SUM.
- MMULT. Multiplying a grid by a column of ones also returns row totals. BYROW says what it does; MMULT makes the reviewer work it out.
- Read one row, one formula. A spilled total is the strictest form of that rule.
