BYROW errors when the LAMBDA returns two columns with HSTACK
Updated
BYROW runs a LAMBDA once per row and must get one value back. HSTACK(SUM(row),AVERAGE(row)) is two values. So is {SUM(row),AVERAGE(row)}. The cell is #N/A or #VALUE!. The tooltip is Single value expected. Nested array results are not supported. The hours are numbers. The return shape is the bug.
A lambda that returns the row itself is BYROW / MAP LAMBDA. This page is the two-metric return: sum and average, built with HSTACK or an array literal. HSTACK of two finished BYROW spills is legal, because each BYROW already returned one column. Keep the Google Sheets UI in English. Helper names stay English: LAMBDA, BYROW, HSTACK.
Recreate it on a blank sheet
Section titled “Recreate it on a blank sheet”- Open a blank spreadsheet. In A1 type
mon, B1tue, C1wed. A22, B22, C21. A30, B34, C33. A45, B41, C41. Three days, three rows. Row totals are5,7,7. Row averages are5/3,7/3,7/3.
One number per row. In E1 type sum_only. In E2 enter =BYROW(A2:C4,LAMBDA(row,SUM(row))). E2:E4 is 5, 7, 7. That column is the control. One scalar each time.
HSTACK inside the lambda. In E6 type hstack_in. In E7 enter =BYROW(A2:C4,LAMBDA(row,HSTACK(SUM(row),AVERAGE(row)))). The cell shows #N/A or #VALUE!. Tooltip: Single value expected. Nested array results are not supported. HSTACK asked each row’s result to be two cells wide. BYROW will not spill a table of rows. Leave E7 broken.
The curly form is the same refusal. In E9 enter =BYROW(A2:C4,LAMBDA(row,{SUM(row),AVERAGE(row)})). Same tooltip. {sum, average} is two cells. Leave E9 broken. If { is Formula parse error before BYROW runs, the array separator for your locale is not a comma. See array literal locale. Fix the separator, and E9 is still the nested-array error.
Two BYROW calls side by side. In G1 type two_calls. Leave G2:H4 empty. In G2 enter =HSTACK(BYROW(A2:C4,LAMBDA(row,SUM(row))),BYROW(A2:C4,LAMBDA(row,AVERAGE(row)))). G2:G4 is 5, 7, 7. H2:H4 is the three averages (1.666…). The HSTACK is outside. Each lambda returned one number. That block is the two-column control.
What is actually wrong
Section titled “What is actually wrong”BYROWcollapses each row to a scalar, then spills those scalars down one column. A lambda that returns two numbers is a nested array.HSTACK,VSTACK,{ }, andSPLITall do that if they sit inside the lambda. E7 and E9.- The same words outside the lambda are a different formula. G2 builds two one-column spills and places them next to each other.
BYROWnever saw a two-cell return. AVERAGE(row)alone would be a legalBYROW. The failure is the pair, not the average. A blank row’sSUMis0. That zero is arithmetic, not this tooltip. See BYROW / MAP LAMBDA.MAPhas the same nested-array rule.=MAP(A2:A4,LAMBDA(h,{h,h*2}))is the other page’s recreate. Do not switch E7 toMAPand returnHSTACK.- A blocked spill of a legal one-column
BYROWis#REF!(Array result was not expanded). E7 never got that far. E7 failed inside the lambda. See array result was not expanded only if the tooltip names a cell.
Leave E7 and E9 broken. Leave E2 as 5 / 7 / 7.
One BYROW per metric, then HSTACK. Keep G2: =HSTACK(BYROW(A2:C4,LAMBDA(row,SUM(row))),BYROW(A2:C4,LAMBDA(row,AVERAGE(row)))). Sums in G, averages in H.
Or one grid from MAKEARRAY. =MAKEARRAY(3,2,LAMBDA(r,c,IF(c=1,SUM(INDEX(A2:C4,r)),AVERAGE(INDEX(A2:C4,r))))) returns the same two columns. Indexes start at 1. See MAKEARRAY LAMBDA if the lambda’s arity is the error instead.
Do not wrap E7 in IFERROR. You still have no average column. See IFERROR vs IFNA.
If the tooltip says Single value expected and the lambda contains HSTACK or { }, move that stack outside BYROW. If the lambda is SUM(row) and the tooltip names a cell below the formula, clear that cell.