Forum Discussion
Mike_OBree
May 28, 2024Copper Contributor
Complex (for me!) lookup formula - help please....
I need an Excel formula to return a lookup value based on date. The lookup dates and values (exchange rates for each date) are arranged in two columns per year. More detail in the spreadsheet attach...
- May 28, 2024
Please try this:
=LET(in,XMATCH(YEAR(A19),$1:$1),XLOOKUP(A19,OFFSET($A$1,1,in-1,365),OFFSET($A$1,1,in,365)))
Mike_OBree
Jun 05, 2024Copper Contributor
see comment in previous message
dscheikey
Jun 05, 2024Bronze Contributor
Hi Mike, the only two mistakes I can recognize are
1) that you have mixed up the names. The solution with offset where you don't have to name the arrays separately is mine.
2) Also, there are no columns for 2025 in the 'fx rates 2002 to date' table.
I would probably have used XLOOKUP() and OFFSET() instead of INDIRECT() and IF():
C29 = LET(InputDate,XLOOKUP(TRUE,OFFSET(C29,0,-2,1,2)>0,OFFSET(C29,0,-2,1,2)),YEARCOL,XMATCH(YEAR(InputDate),'fx rates 2002 to date'!$2:$2),XLOOKUP(InputDate,OFFSET('fx rates 2002 to date'!$A$2,1,YEARCOL-1,365),OFFSET('fx rates 2002 to date'!$A$2,1,YEARCOL,365)))
- Mike_OBreeJun 06, 2024Copper Contributor
dscheikey -
Very slick use of XLOOKUP and OFFSET to reference the InputDate Cell !
However, if you copy/paste the Cell with the formula included in it to another excel file, although the "C29" reference will adjust accordingly, the sheet name 'fx rates 2002 to date will now have the originating file name appended to it.
On the other hand, if you copy the formula from the cell edit window, the paste correctly keeps just the 'fx rates 2002 to date' sheet name (without the wrong file name), but then the 'C29' will not adjust appropriately.
My version using "INDIRECT" did not suffer from that problem.
Does this make any sense?- dscheikeyJun 06, 2024Bronze Contributor
Yes, that makes sense! If you copy the formula to another worksheet, it is best to do this via the edit bar. Then you have to adjust the worksheet names and cell C29 once. That was just an example. So adjust the C29 by the cell in which the formula is located. If you use it in C1, you must replace C29 with C1.
But the Indirect() also works.
- Mike_OBreeJun 05, 2024Copper Contributor
dscheikey -
1) You are right on, I mixed up the names everywhere (even for "Best Response")- so sorry ... I will try to rectify that!
2) You are right ... there are no columns for 2025 in the table... but I did that on purpose just to ensure I would get a "#N/A" value when appropriate.
I'll take a look at your "XLOOKUP() and OFFSET() instead of INDIRECT() and IF()" variation:
thanks again.