Search code examples
excelexcel-formulaoffice365excel-365

Can Lambda functions use text references passed from the ByCol function?


While writing a function that gets and transforms data from an array of text-based references (e.g. {"ref1", "ref2", ...}) I discovered the below problem.

=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(cellRef)))

Returns

FALSE

As far as I can tell, this is the simplest form of the problem where I replaced my actual data calculation with a simple check on the validity of the reference.

I cannot pivot away from iterating over text-based references as the real references are table columns (e.g. table1[A], table2[A], ...) stored in a 1-dimensional array. At first, I tried to replace my structured references with plain A1 notation, but that was only an intermediary step to the above issue—ISREF() within BYCOL(...Lambda(...)) returns FALSE.

I have tried using INDIRECT(), T(), INDEX(), and CELL() in various (perhaps silly) ways that include:

=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(INDIRECT(cellRef))))
=BYCOL({"A1"}, LAMBDA(cellRef, INDIRECT(ISREF(cellRef))))
=BYCOL({"INDIRECT(A1)"}, LAMBDA(cellRef, ISREF(cellRef)))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(INDIRECT(T(cellRef)))))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(CELL("address", cellRef))))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(INDIRECT(CELL("address", cellRef)))))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(CELL("address", cellRef))))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(INDEX(cellRef, 1))))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(INDEX(cellRef, 1, 1))))
=BYCOL({"A1"}, LAMBDA(cellRef, ISREF(INDEX(cellRef, 0))))

But they all evaluate to FALSE. Note that the last few using INDEX() still fail. I was hoping this answer would help.

If there is some unique syntax required to make these functions work together or some logic that prevents you from iterating over references in this way, please let me know.


Solution

  • Check Array For Valid Range References

    • You were just an INDIRECT too short in your last three formulas.

    Hard-Coded

    • You could use...

      =BYCOL({"A1"}, LAMBDA(cellRef,ISREF(INDEX(INDIRECT(cellRef),1))))
      

      ... or more obviously

      =BYCOL({"A1","B1","AAA","D1048576","E1048577"},LAMBDA(cellRef,ISREF(INDEX(INDIRECT(cellRef),1))))
      

      ... yielding in

      {TRUE,TRUE,FALSE,TRUE,FALSE}
      

    Dynamic

    =A2:A3&"["&B1:G1&"]"                    
    =MAP(B2:G3,LAMBDA(cellRef,ISREF(INDEX(INDIRECT(cellRef),1))))                   
    or:
    =MAP(B2#,LAMBDA(cellRef,ISREF(INDEX(INDIRECT(cellRef),1))))                 
    

    enter image description here