Forum Discussion
Dynamic spill filtered based on other spill
There is a catch. The products associated with each account form a list, and so the table you are trying to create is a nested array. Because of limitations build into Excel to retain backward compatibility, this is not properly supported. The workaround is to use REDUCE and built the array step by step using VSTACK.
=LET(
account, UNIQUE(FILTER(MasterData[Account Name], MasterData[Rep] = SelectRep)),
products, REDUCE("", account,
LAMBDA(list, ac,
VSTACK(list, TRANSPOSE(FILTER(MasterData[Product], MasterData[Account Name] = ac)))
)
),
HSTACK(account, IFNA(DROP(products, 1), ""))
)
It is possible to make the worksheet formula more readable by using a further Lambda function to return the lists of products using
= LET(
account, UNIQUE(FILTER(MasterData[Account Name], MasterData[Rep] = SelectRep)),
products, MultipleFilterλ(MasterData[Product], MasterData[Account Name], account),
HSTACK(account, IFNA(DROP(products, 1), ""))
)
but the simplification is achieved at the expense of having to define a further Lambda function MultipleFilterλ
= LAMBDA(products, accounts, selectedACs,
REDUCE("", selectedACs,
LAMBDA(list, ac, VSTACK(list, TRANSPOSE(FILTER(products, accounts = ac)))
)
)
PeterBartholomew1 this is incredible! And reduces me to one spill formula instead of two. I'll need to do some reading to understand it, as VSTACK, HSTACK, REDUCE, and IFNA are new to me, but it works perfectly. I greatly appreciate you, both for solving my problem and helping me learn more about how to create better dynamic array functions!