Lookup value based on nearest date & column heading in another table

Gwill1983

Board Regular
Joined
Oct 24, 2018
Messages
123
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Tricky one to describe, but I will try my best.

I am trying to create an exchange rate table that looks up the exchange rate based on a date that the order was placed. I have my very rough tables below:

1674056330788.png


In cell B2, I would like to be able to lookup the exchange rate for the currency added into C2 (which will match one of the column headings in the 2nd table) within the 2nd table returning the value in the table based on the date closest in the past to the date in A2.

I am really stumped by this one, so any help is much appreciated!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I have solved this myself!

=IF([@Currency]="Pounds",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,2,0),IF([@Currency]="Euro",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,3,0),IF([@Currency]="Yen",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,4,0),IF([@Currency]="Dollar",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,5,0)))))
 
Upvote 0
Solution
I have solved this myself!
Glad you figured something out. :)

Here are a couple of shorter options (columns C & D) that seem to produce the same results as your formula (column B)

Gwill1983.xlsm
ABCDEFGHIJKL
1date of bookingexchange rateexchange rate 2exchange rate 3CurrencyDatePoundsEuroYenDollar
21/01/2022#N/A#N/A#N/AYen1/02/20221101001000
36/04/2022111Pounds1/06/20222202002000
43/09/2022303030Euro1/08/20223303003000
52/12/2022300030003000Dollar1/01/20234404004000
610/01/2023400400400Yen
7
Sheet1
Cell Formulas
RangeFormula
B2:B6B2=IF([@Currency]="Pounds",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,2,0),IF([@Currency]="Euro",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,3,0),IF([@Currency]="Yen",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,4,0),IF([@Currency]="Dollar",VLOOKUP(MAX((Table3[Date]<[@[date of booking]])*Table3[Date]),Table3,5,0)))))
C2:C6C2=VLOOKUP([@[date of booking]],CHOOSECOLS(Table3,1,MATCH([@Currency],Table3[#Headers],0)),2)
D2:D6D2=XLOOKUP([@[date of booking]],Table3[Date],INDIRECT("Table3["&[@Currency]&"]"),,-1)
 
Upvote 0

Forum statistics

Threads
1,215,619
Messages
6,125,871
Members
449,267
Latest member
ajaykosuri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top