Get closest value for nearest date

niko1823

New Member
Joined
Dec 12, 2017
Messages
6
From the below.
worksheet1 : In worksheet1 "duty" column. I need to find out what duty "worker" last had during work_order_date. Bill on work_order_date 08/01/2017 & 08/05/2017 should report back as "welder" because he was not yet a manager until 8/15/2017. worksheet1 Bill work_order_date 09/20/2017 "duty" column should be "manager" because he was last reported as manager in worksheet2 on 8/15. he was not yet an owner until 10/20.



worksheet1worksheet2
workerwork_order_datedutyworkeremployment_dateduty
bill08/01/2017bill07/30/2017welder
bill08/05/2017bill08/15/2017manager
bill09/20/2017bill10/20/2017owner
jan10/31/2017jan11/05/2017client

<tbody>
</tbody>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi. See if this works for you:

=IFERROR(LOOKUP(2,1/((Sheet2!$A$2:$A$5=A2)*(Sheet2!$B$2:$B$5<=B2)),Sheet2!$C$2:$C$5),"not employed")
 
Upvote 0
I just did a vlookup for the information regarding Bill in the duty column : =VLOOKUP(B3,Sheet2!$C$3:$D$7,2,1) so looking up by date but with a TRUE Statement at the end you will get the last row where the range value is <= the lookup value so it came out correctly. The reason i started my dates one column over though is because of the other employee Jan. if you want to differentiate them you can concatenate worksheet two in column A so =A2&B2 which just combines their name and date then you can do =VLOOKUP(A3&B3,Sheet2!$A$3:$D$7,4,1). The only issue here is that on worksheet 2 the only data you have for Jan is after her work order date of 10/31 so it will default to just the closest date which will label her as owner since it was before 10/31. So the workers would need a label prior to the worksheet 1 date. Hope that makes sense.
 
Upvote 0
=IFERROR(LOOKUP(2,1/((Sheet2!$A$2:$A$5=A2)*(Sheet2!$B$2:$B$5<=B2)),Sheet2!$C$2:$C$5),"not employed")

worked great just needed to sort both workbooks by date (oldest to newest) or else it wouldn't bring back the correct duty from worksheet2.
 
Upvote 0

Forum statistics

Threads
1,213,539
Messages
6,114,221
Members
448,554
Latest member
Gleisner2

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