Forum Discussion
EllenKristina
Dec 09, 2022Copper Contributor
Lookup with more than one criteria
Hi, I have an Excel sheet with several transactions in different currencies and on different dates. In the next sheet I have an overview of all the different currencies on each day for a given peri...
PeterBartholomew1
Dec 12, 2022Silver Contributor
Another strategy is to blank out the dates with that correspond to the wrong currency and then use XLOOKUP to return the exact match from the remaining dates or, failing that, the next latest.
= LET(
filteredDates, IF(CXRateTbl[Code]=[@Code], CXRateTbl[Date]),
XLOOKUP( [@Date], filteredDates, CXRateTbl[Rate],"No match",1)
)Placed within the Transactions Table the formula will propagate down the column. If used outside the Table one should aim at returning results as a dynamic array. This require the use of MAP and LAMBDA to get the inequalities between two arrays to work correctly
= MAP(Transactions[Date], Transactions[Code],
LAMBDA(date,code,
LET(
filteredDates, IF(CXRateTbl[Code]=code, CXRateTbl[Date]),
XLOOKUP(date, filteredDates, CXRateTbl[Rate],"No match",1)
)
)
)