Forum Discussion

Greg_Hullender's avatar
Greg_Hullender
Copper Contributor
Dec 14, 2025

TOCOL/TOROW Treat Thunks as Errors

I just reported a bug to Excel in which the TOROW and TOCOL functions, if asked to delete errors, will also delete valid thunks. ISERROR returns FALSE when presented with a thunk, so, arguably, TOCOL shouldn't treat it as an error either. I'm running Office 365 on Windows 11 on a Samsung Yoga laptop.

Steps to reproduce: Paste this into a single cell in a spreadsheet:

=LET(th, VSTACK(LAMBDA(4)), (@TOCOL(th,2))())

Expected behavior: should return 4. (Delete the ",2" and it does exactly that.)

Actual behavior: #CALC error

Impact: Breaks workflows for SCAN, MAP, BYCOL, and BYROW

Workaround: Use FILTER and ISERROR

Details: An Excel "thunk" is a degenerate LAMBDA with no parameters. So if we used LET to make f equal to LAMBDA(4), then f() would always return 4. If a thunk is the final result of a function, it generates a #CALC error, but it's fine for intermediate results.

This seems useless, but it's the only way to get functions like SCAN, MAP, and BYROW/COL to return anything but a scalar.

For example, I have a piece of code where I need to repeatedly square a large matrix and save the values for further processing. If I get a zero value, I can save a lot of processing by "aborting" the operation. Since you can't abort a SCAN, I just return #NA. Then I'd like to use TOCOL(result, 2) to strip off the unnecessary values. But TOCOL discards everything.

I can work around this by using a combination of ISERROR and FILTER, but I shouldn't have to.

2 Replies

  • I had somewhat resigned myself to the idea that I couldn't use the TOCOL error criterion to filter errors without also taking out the #CALC! errors that represent functions.  I now think I was wrong to settle for that!  As you have observed, ISERROR does not treat functions as errors so why should TOCOL?

    In a functional programming environment in which functions are first class citizens it is simply wrong that TOCOL should treat them as errors.

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    Why something like

    =LET(th, VSTACK(LAMBDA(4)), TOCOL((@th)(),2) )
    
    =LET(th, LAMBDA(SCAN(0, SEQUENCE(4), LAMBDA(a,v,IF(v=3, NA(), a+v)))), TOCOL( th(),2) )

    doesn't work?

Resources