Forum Discussion
Let statement display multiple results in separate columns
With such problems, what is best depends on what is intended calculation. If it is just a case of appending the tables, I have an add-in from Charles Williams that does the append tables in one step.
= VSTACK("",Table1,Table2,Table3)Without such a function, life gets a bit harder. I tend to build the solution step by step using Lambda functions. A starting point might be a function to return a Table by index. As an aside, I regard the use of direct referencing as something of an 'own goal'. If the range is oversized, one has the extra task of removing blank records. If the size is not sufficient, it represents a Latent Error. That is a calculation that gives the correct results for now but, as things go on, may eventually cause an error if the range is not increased to match the data.
"Read a table:" Tableλ
= LAMBDA(dept,
CHOOSE(dept,
Table1,
Table2,
Table3)
)
"Return row count for table:" Rowsλ
= LAMBDA(dept, ROWS(Tableλ(dept)))
"Return a single record by table and row indices:" Recordλ
= LAMBDA(department,recordnum,
INDEX(Tableλ(department),recordnum,0))The awkward steps are accumulating the table row counts so that each output row can be mapped back to a table and record by index.
= LET(
nRows, MAP({1;2;3}, LAMBDA(dept,Rowsλ(dept))),
accRows, SCAN(0,nRows,LAMBDA(tRows,n,tRows+n)) - nRows,
totalRows, SUM(nRows),
MAKEARRAY(totalRows,nCol,
LAMBDA(k,col,
LET(
dept, XMATCH(k-1,accRows,-1),
k₁, k - XLOOKUP(k-1,accRows,accRows,,-1),
INDEX(Recordλ(dept,k₁),col)
)
)
)
)Again, as an aside, it is not always necessary to append the tables. Sometimes calculations such as lookups or filters can be carried out on a 'by table' basis, and the results aggregated rather than the individual tables.