Update table based on closest match on date

dalahans

New Member
Joined
Jun 7, 2018
Messages
2
Hi

I have got 2 tables: "Orderlines" and "Pricedates"

Orderlines
Date of purchase Itemnr Price
2018-01-01 A 0
2018-01-02 A 0
2018-01-03 A 0
2018-01-04 A 0
2018-01-05 A 0
2018-01-06 A 0
2018-01-07 A 0
2018-01-08 A 0
2018-01-09 A 0
2018-01-10 A 0
2018-01-11 A 0
2018-01-12 A 0
2018-01-13 A 0
2018-01-14 A 0
2018-01-15 A 0
2016-01-15 B 0
2017-06-22 B 0
2018-01-05 B 0
2018-03-14 B 0



Pricedates
Item Price date Price
A 2018-01-02 2
A 2018-01-07 7
A 2018-01-11 11
A 2018-01-15 15
A 2018-01-22 22
A 2018-01-23 23
B 2016-01-01 1000
B 2017-01-01 2000
B 2018-01-01 3000
B 2018-02-02 4000
B 2018-03-03 5000


I need a query to update the field "Price" in the "Orderlines-table"
It should pick the price from the "Pricedate"-table at the valid date, itemnumber by itemnumber
The valid date is a date <= "Date of purchase"


This is what the result should look like:

Date of purchase Itemnr Price
2018-01-01 A
2018-01-02 A 2
2018-01-03 A 2
2018-01-04 A 2
2018-01-05 A 2
2018-01-06 A 2
2018-01-07 A 7
2018-01-08 A 7
2018-01-09 A 7
2018-01-10 A 7
2018-01-11 A 11
2018-01-12 A 11
2018-01-13 A 11
2018-01-14 A 11
2018-01-15 A 15
2016-01-15 B 1000
2017-06-22 B 2000
2018-01-05 B 3000
2018-03-14 B 5000


Any help is appreciated


// Hans
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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