Forum Discussion
Another issue with BYROW
- Mar 24, 2023
Since you use BYROW() each element of SEQUENCE(2) is passed to lambda as an array, i.e. it will be like
INDEX( {1,2;3,4},{i},)
To return entire row in this case you shall use column numbers as array as well
=INDEX({1,2;3,4},{1},{1,2})
MAP() returns single value of the array element, thus it works.
With BYROW() - yes, we need to transform an array to single value, as "@i" or INDEX(i,1,1).
Hi David,
Not sure, but it could be the case that LAMBDAs passed to functions such as BYROW and which do not make use of the implicit intersection operator are first computed for each iteration and stored in an internal array prior to being output.
This would fit in with the known issue of INDEX not being able to internally store an array of rows/columns when passed a zero for either its row_num or column_num parameter. In legacy Excel, for example, even though
=SUM(INDEX({1,2;3,4},1,0))
and
=SUM(INDEX({1,2;3,4},2,0))
would resolve to 3 and 7 as desired, it was never possible to coerce Excel to return both of the entire rows in a single construction. I tried many variations on
=SUM(INDEX({1,2;3,4},N(IF(1,{1;2})),0))
but never managed to achieve it.
Perhaps newer functions such as CHOOSEROWS, by virtue of expecting only a single parameter, as opposed to INDEX expecting two, do not suffer this drawback. That said, your workaround involving inclusion of the implicit intersection operator with INDEX is fascinating - seemingly forcing INDEX into behaving as it should.
Hopefully someone else will offer more insight.
Regards