Forum Discussion
AriBouaniche
Sep 09, 2023Copper Contributor
Filter array based on other filtered array as a lookup value
Hi, I am trying to achieve something I have never done before. I want to filter a huge array, based on the result of another filtered array, in an OR manner. Let me explain... I have a list o...
PeterBartholomew1
Sep 09, 2023Silver Contributor
Congratulations on getting to a solution!
The problem with your first formula is that you finish up searching the array of teachers against an array of schools as the criterion. Logically, you should be able to achieve this school by school using MAP but unfortunately Microsoft managed to make a disastrous error in deciding that a nested arrays would be an error rather than the natural result of almost every formula!
One way of circumventing the problem is to use REDUCE to run through the filtered list of schools, stacking the result as one goes.
= LET(
schools_in_group, FILTER(School_IDs,School_Groups=group),
REDUCE("Teachers", schools_in_group,
LAMBDA(list,school,
VSTACK(list, FILTER(teacher, schools_in_teacher_table=school))
)
)
)(a few errors implementing you names but broadly the same)
The other option is to perform a single FILTER and build the complexity into the criterion, as you have done.
= LET(
school_in_group, XLOOKUP(schools_in_teacher_table, School_IDs, School_Groups = group),
FILTER(teacher, school_in_group)
)