arraysexcelfilterlambdalet

Excel LET function to return filtered values of various size based on a criteria row by row


I am working with this data set:

enter image description here

What I need is to return the list of values corresponding to to each unique category. Seems straight forward and I generated this using excel formula

=TRANSPOSE(FILTER($B$2:$B$11,$A$2:$A$11=D2))) 

by dragging down. Here's the output:

enter image description here

What I need eventually is to use the list of values for each of the categories, as a variable of LET function, to output everything all at once as a part of bigger formula. I have tested this set of solutions:

  1. =LET(AllCategories,$A$2:$A$11,values,$B$2:$B$11,myCategories,D2:D4,output,MAP(myCategories,LAMBDA(x,TRANSPOSE(FILTER(values,AllCategories=x)))),output)

  2. =LET(categories,D2:D5,BYROW(categories,LAMBDA(category,HSTACK(category,FILTER($B$2:$B$11,$A$2:$A$11=category)))))

  3. =LET( uniqueCategories, UNIQUE(A2:A11), BYROW(uniqueCategories, LAMBDA(category, HSTACK(category, TRANSPOSE(FILTER(B2:B11, A2:A11=category))))) )

  4. =LET(uniqueCategories,UNIQUE(A2:A11),valuesList,MAP(uniqueCategories, LAMBDA(category, HSTACK(category, FILTER($B$2:$B$11, $A$2:$A$11=category)))), valuesList)

The goal of formulas 1-4 was to go by each unique category row by row, and return values based on category in col A. In each case I have got the #CALC! as a result.

Looking for a help here. I've googled the problem, eployed ( :) ) chatGPT to try to figure it out and still cannot solve it.


Solution

  • using REDUCE/LAMBDA:

    =IFERROR(DROP(REDUCE("",UNIQUE(A2:A11),LAMBDA(z,y,VSTACK(z,HSTACK(y,TRANSPOSE(FILTER(B2:B11,A2:A11=y)))))),1),"")
    

    enter image description here