Let statement display multiple results in separate columns

%3CLINGO-SUB%20id%3D%22lingo-sub-3215588%22%20slang%3D%22en-US%22%3ELet%20statement%20display%20multiple%20results%20in%20separate%20columns%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3215588%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3EThanks%20to%20any%20one%20who%20can%20help.%20I%20Have%20a%20Let%20formula%20that%20pulls%20data%20from%203%20separate%20sheets%20and%20stacks%20it%20in%20one%20column%20on%20a%20separate%20sheet.%20I%20also%20want%20to%20add%20another%20variable%20to%20the%20let%20formula%20that%20uses%20xlookup%20on%20the%20first%20array.%20Basically%20its%20a%20list%20of%20names%20it%20would%20display%20a%20rate%20that's%20associated%20with%20that%20name%20from%20another%20sheet%20and%20the%20final%20result%20of%20the%20let%20statement%20would%20display%202%20columns%20original%20being%20the%20names%20and%20second%20being%20the%20rate.%20The%20following%20is%20the%20let%20formula%20that%20pulls%20the%20names.%20Its%20the%20addition%20of%20the%20second%20column%20that%20I'm%20having%20issues%20with%20any%20help%20would%20be%20appreciated.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DLET(%0AList%2CSORT(IF(ISBLANK(EducationData!B72%3AB239)%2C%22Empty%22%2CEducationData!B72%3AC239)%2C1%2C1)%2C%0AList2%2CSORT(IF(ISBLANK(AdminData!B4%3AC35)%2C%22Empty%22%2CAdminData!B4%3AC35)%2C1%2C1)%2C%0AList3%2CSORT(IF(ISBLANK(TherapiesData!C87%3AD291)%2C%22Empty%22%2CTherapiesData!C87%3AD291)%2C1%2C1)%2C%0AFltr%2CCONCATENATE(FILTER(FILTER(List%2CINDEX(List%2C0%2C1)%26lt%3B%26gt%3B%22Empty%22)%2C%7B1%2C0%7D)%2C%22%2C%20%22%2CFILTER(FILTER(List%2CINDEX(List%2C0%2C1)%26lt%3B%26gt%3B%22Empty%22)%2C%7B0%2C1%7D))%2C%0AFltr2%2CCONCATENATE(FILTER(FILTER(List2%2CINDEX(List2%2C0%2C1)%26lt%3B%26gt%3B%22Empty%22)%2C%7B1%2C0%7D)%2C%22%2C%20%22%2CFILTER(FILTER(List2%2CINDEX(List2%2C0%2C1)%26lt%3B%26gt%3B%22Empty%22)%2C%7B0%2C1%7D))%2C%0AFltr3%2CCONCATENATE(FILTER(FILTER(List3%2CINDEX(List3%2C0%2C1)%26lt%3B%26gt%3B%22Empty%22)%2C%7B1%2C0%7D)%2C%22%2C%20%22%2CFILTER(FILTER(List3%2CINDEX(List3%2C0%2C1)%26lt%3B%26gt%3B%22Empty%22)%2C%7B0%2C1%7D))%2C%0ANumCols%2C%20COLUMNS(Fltr)%2C%0ARowsA%2C%20ROWS(Fltr)%2C%0ARowsB%2C%20ROWS(Fltr2)%2C%0ARowsC%2C%20ROWS(Fltr3)%2C%0ASeqCol%2C%20SEQUENCE(RowsA%2B%20RowsB%2B%20RowsC)%2C%0ASeqRow%2C%20SEQUENCE(1%2C%20NumCols)%2C%0AResult%2C%20IF(SeqCol%20%26lt%3B%3D%20RowsA%2C%20INDEX(Fltr%2CSeqCol%2C%20SeqRow)%2CIF(SeqCol%20%26lt%3B%3D%20(RowsA%20%2B%20RowsB)%2CINDEX(Fltr2%2CSeqCol%20-%20RowsA%2C%20SeqRow)%2CINDEX(Fltr3%2CSeqCol-(RowsA%20%2B%20RowsB)%2CSeqRow)))%2C%0AResult%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3215588%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3215734%22%20slang%3D%22en-US%22%3ERe%3A%20Let%20statement%20display%20multiple%20results%20in%20separate%20columns%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3215734%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1076230%22%20target%3D%22_blank%22%3E%40dshawSLDC%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20to%20say%2C%20first%2C%20that%20what%20you've%20written%20is%20the%20most%20impressive%20LET%20formula%20I've%20ever%20seen.%20That%20you're%20having%20trouble%20in%20the%20aftermath%20of%20successfully%20doing%20that%20first%20step%20is%2C%20in%20itself%2C%20daunting.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wonder%2C%20though%2C%20why%20you%20think%20it%20necessary%20to%20incorporate%20an%20XLOOKUP%20into%20that%20already%20impressive%20LET%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20XLOOKUP%20not%20work%20simply--cleanly%2C%20clearly%2C%20and%20(incidentally)%20more%20readily%20maintainable--as%20the%20sole%20formula%20in%20that%20second%20column%3F%20There's%20no%20Excel%20commandment%20that%20I'm%20aware%20of%20that%20encourages%20us%20to%20put%20all%20the%20functionality%20into%20a%20single%20formula.%20LET%20is%20powerful%2C%20yes%2C%20but%20there's%20value%20in%20simplicity%20too.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3222047%22%20slang%3D%22en-US%22%3ERe%3A%20Let%20statement%20display%20multiple%20results%20in%20separate%20columns%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3222047%22%20slang%3D%22en-US%22%3EFirst%20thank%20you%20for%20the%20Compliment.%20Second%20the%20reason%20I%20need%20to%20put%20in%20one%20formula%20is%20I%20need%20both%20columns%20to%20work%20dynamically%20as%20the%20data%20changes.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3222579%22%20slang%3D%22en-US%22%3ERe%3A%20Let%20statement%20display%20multiple%20results%20in%20separate%20columns%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3222579%22%20slang%3D%22en-US%22%3E%3CP%3EUnless%20I'm%20mistaken%2C%20XLOOKUP%20in%20the%20second%20column%20would%20work%20in%20real-time%20(i.e.%2C%20dynamically)%20based%20on%20what's%20in%20the%20first%20column.%20Just%20embed%20it%20in%20an%20IFERROR%20and%20copy%20it%20down%20to%20more%20rows%20than%20you%20expect%2C%20and%20have%20it%20produce%20a%20blank%20if%20it%20doesn't%20produce%20a%20value%20based%20on%20the%20lookup.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3222741%22%20slang%3D%22en-US%22%3ERe%3A%20Let%20statement%20display%20multiple%20results%20in%20separate%20columns%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3222741%22%20slang%3D%22en-US%22%3EYes%20I%20agree%20I%20can%20do%20that%20but%20I%20was%20hoping%20to%20have%20it%20spill%20with%20the%20other%20formula.%20So%20I%20can%20reference%20the%20spill%20data%20elsewhere%20if%20I%20do%20the%20xlookup%20and%20drag%20down%20in%20the%20second%20column%20and%20the%20original%20data%20get%20larger%20I%20will%20have%20to%20continue%20to%20drag%20down%20every%20time%20the%20data%20changes.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3223333%22%20slang%3D%22en-US%22%3ERe%3A%20Let%20statement%20display%20multiple%20results%20in%20separate%20columns%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3223333%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1076230%22%20target%3D%22_blank%22%3E%40dshawSLDC%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DLET(%0AList%2CCHOOSE(%7B1%2C2%2C3%2C4%2C5%2C6%2C7%7D%2CEducationData!B72%3AB239%2CEducationData!C72%3AC239%2CEducationData!E72%3AE239%2CEducationData!F72%3AF239%2CEducationData!G72%3AG239%2CEducationData!H72%3AH239%2CEducationData!J72%3AJ239)%2C%0AListEmp%2CSORT(IF(ISBLANK(List)%2C%22Empty%22%2CList)%2C1%2C1)%2C%0AListCol%2CINDEX(ListEmp%2C%2C3)%2C%0AListCol)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Contributor

Hello,

Thanks to any one who can help. I Have a Let formula that pulls data from 3 separate sheets and stacks it in one column on a separate sheet. I also want to add another variable to the let formula that uses xlookup on the first array. Basically its a list of names it would display a rate that's associated with that name from another sheet and the final result of the let statement would display 2 columns original being the names and second being the rate. The following is the let formula that pulls the names. Its the addition of the second column that I'm having issues with any help would be appreciated.

=LET(
List,SORT(IF(ISBLANK(EducationData!B72:B239),"Empty",EducationData!B72:C239),1,1),
List2,SORT(IF(ISBLANK(AdminData!B4:C35),"Empty",AdminData!B4:C35),1,1),
List3,SORT(IF(ISBLANK(TherapiesData!C87:D291),"Empty",TherapiesData!C87:D291),1,1),
Fltr,CONCATENATE(FILTER(FILTER(List,INDEX(List,0,1)<>"Empty"),{1,0}),", ",FILTER(FILTER(List,INDEX(List,0,1)<>"Empty"),{0,1})),
Fltr2,CONCATENATE(FILTER(FILTER(List2,INDEX(List2,0,1)<>"Empty"),{1,0}),", ",FILTER(FILTER(List2,INDEX(List2,0,1)<>"Empty"),{0,1})),
Fltr3,CONCATENATE(FILTER(FILTER(List3,INDEX(List3,0,1)<>"Empty"),{1,0}),", ",FILTER(FILTER(List3,INDEX(List3,0,1)<>"Empty"),{0,1})),
NumCols, COLUMNS(Fltr),
RowsA, ROWS(Fltr),
RowsB, ROWS(Fltr2),
RowsC, ROWS(Fltr3),
SeqCol, SEQUENCE(RowsA+ RowsB+ RowsC),
SeqRow, SEQUENCE(1, NumCols),
Result, IF(SeqCol <= RowsA, INDEX(Fltr,SeqCol, SeqRow),IF(SeqCol <= (RowsA + RowsB),INDEX(Fltr2,SeqCol - RowsA, SeqRow),INDEX(Fltr3,SeqCol-(RowsA + RowsB),SeqRow))),
Result
)
10 Replies

@dshawSLDC 

 

Have to say, first, that what you've written is the most impressive LET formula I've ever seen. That you're having trouble in the aftermath of successfully doing that first step is, in itself, daunting.

 

I wonder, though, why you think it necessary to incorporate an XLOOKUP into that already impressive LET?

 

Could XLOOKUP not work simply--cleanly, clearly, and (incidentally) more readily maintainable--as the sole formula in that second column? There's no Excel commandment that I'm aware of that encourages us to put all the functionality into a single formula. LET is powerful, yes, but there's value in simplicity too.

First thank you for the Compliment. Second the reason I need to put in one formula is I need both columns to work dynamically as the data changes.

Unless I'm mistaken, XLOOKUP in the second column would work in real-time (i.e., dynamically) based on what's in the first column. Just embed it in an IFERROR and copy it down to more rows than you expect, and have it produce a blank if it doesn't produce a value based on the lookup.

Yes I agree I can do that but I was hoping to have it spill with the other formula. So I can reference the spill data elsewhere if I do the xlookup and drag down in the second column and the original data get larger I will have to continue to drag down every time the data changes.

I might have found away. but i have hit a little snag. Does anyone know how to reference a column inside an array in a let statement?

 

=LET(
List,CHOOSE({1,2,3,4,5,6,7},EducationData!B72:B239,EducationData!C72:C239,EducationData!E72:E239,EducationData!F72:F239,EducationData!G72:G239,EducationData!H72:H239,EducationData!J72:J239),
ListEmp,SORT(IF(ISBLANK(List),"Empty",List),1,1),
ListEmp)

 

In the ListEmp Variable where it references the list variable. How do I specify a specific column instead of the whole array.  

 

Thanks

@dshawSLDC 

For example:

=LET(
List,CHOOSE({1,2,3,4,5,6,7},EducationData!B72:B239,EducationData!C72:C239,EducationData!E72:E239,EducationData!F72:F239,EducationData!G72:G239,EducationData!H72:H239,EducationData!J72:J239),
ListEmp,SORT(IF(ISBLANK(List),"Empty",List),1,1),
ListCol,INDEX(ListEmp,,3),
ListCol)
Thanks That was very helpful. Quick question do you know if you can use the choose statement on array?

@dshawSLDC 

Not sure what you mean.

The syntax of CHOOSE is CHOOSE(index, value1, value2 ,...)

CHOOSE({1,2}, array1, array2) works, but CHOOSE({1,2}, array) doesn't.

Thanks everyone. I was able to get it to pull and display correctly the following is the final Let Statement.

=LET(
List,SORT(IF(ISBLANK(EducationData!B72:B239),"Empty",EducationData!B72:J239),1,1),
List2,SORT(IF(ISBLANK(AdminData!B4:B35),"Empty",AdminData!B4:L35),1,1),
List3,SORT(IF(ISBLANK(TherapiesData!C87:C291),"Empty",TherapiesData!C87:M291),1,1),
Fltr,FILTER(List,INDEX(List,0,1)<>"Empty"),
Fltr2,FILTER(List2,INDEX(List2,0,1)<>"Empty"),
Fltr3,FILTER(List3,INDEX(List3,0,1)<>"Empty"),
FltrCol,CHOOSE({1,2,3,4,5,6,7},INDEX(Fltr,,1),INDEX(Fltr,,2),INDEX(Fltr,,5),INDEX(Fltr,,4),INDEX(Fltr,,6),INDEX(Fltr,,7),INDEX(Fltr,,8)),
FltrCol2,CHOOSE({1,2,3,4,5,6,7},INDEX(Fltr2,,1),INDEX(Fltr2,,2),INDEX(Fltr2,,5),INDEX(Fltr2,,10),INDEX(Fltr2,,7),INDEX(Fltr2,,8),INDEX(Fltr2,,11)),
FltrCol3,CHOOSE({1,2,3,4,5,6,7},INDEX(Fltr3,,1),INDEX(Fltr3,,2),INDEX(Fltr3,,5),INDEX(Fltr3,,3),INDEX(Fltr3,,7),INDEX(Fltr3,,8),INDEX(Fltr3,,10)),

NumCols, COLUMNS(FltrCol),
RowsA, ROWS(FltrCol),
RowsB, ROWS(FltrCol2),
RowsC, ROWS(FltrCol3),
SeqCol, SEQUENCE(RowsA+ RowsB+ RowsC),
SeqRow, SEQUENCE(1, NumCols),
Result, IF(SeqCol <= RowsA, INDEX(FltrCol,SeqCol, SeqRow),IF(SeqCol <= (RowsA + RowsB),INDEX(FltrCol2,SeqCol - RowsA, SeqRow),INDEX(FltrCol3,SeqCol-(RowsA + RowsB),SeqRow))),
Result
)

@dshawSLDC 

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.