Restrict to last occurrence using OFFSET

paulm88

New Member
Joined
Jun 13, 2017
Messages
15
Problem.JPG

I am trying to find how to return the workers pay the maximum number of weeks after their start date. As you can see in the example below, I have tried to OFFSET by the number of weeks (G2). However, this is returning the pay for worker Bob instead of the last instance of Paul (£25). I basically need to restrict the lookup to the worker no matter if the number of weeks exceeds the instances of column A.


Problem.JPG
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
[TABLE="width: 500"]
<tbody>[TR]
[TD]Worker
[/TD]
[TD]Week[/TD]
[TD]Pay[/TD]
[TD][/TD]
[TD]Worker[/TD]
[TD]Start Week[/TD]
[TD]Max Weeks[/TD]
[TD]Final Pay[/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]18/03/17[/TD]
[TD]£5[/TD]
[TD][/TD]
[TD]Paul[/TD]
[TD]01/04/17[/TD]
[TD]5[/TD]
[TD]{=OFFSET(INDEX(C:C,MATCH(E2&F2,A:A&B:B,0)),G2,0)}
[/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]25/03/17[/TD]
[TD]£10[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]01/04/17[/TD]
[TD]£15[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]08/04/17[/TD]
[TD]£20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]15/04/17[/TD]
[TD]£25[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]01/04/17[/TD]
[TD]£40[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]08/04/17[/TD]
[TD]£50[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]15/04/17[/TD]
[TD]£60[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]22/04/17[/TD]
[TD]£70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
If im understanding correctly try this:

=LOOKUP(2,1/((A2:A100=E5)*(B2:B100<=(F5+G5*7))),C2:C100)
 
Upvote 0
Your formula works perfectly in theory and returns the value I would expect. However, the example I provided was poor! I was using OFFSET as it is not always the case that the dates will be every week, I've changed the example below.


[TABLE="width: 500"]
<tbody>[TR]
[TD]Worker[/TD]
[TD]Week[/TD]
[TD]Pay[/TD]
[TD][/TD]
[TD]Worker[/TD]
[TD]Start Week[/TD]
[TD]Max payments[/TD]
[TD]Final Pay[/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]01/03/17[/TD]
[TD]£5[/TD]
[TD][/TD]
[TD]Paul[/TD]
[TD]06/09/17[/TD]
[TD]5[/TD]
[TD]{=OFFSET(INDEX(C:C,MATCH(E2&F2,A:A&B:B,0)),G2,0)}[/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]07/06/17[/TD]
[TD]£10[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]06/09/17[/TD]
[TD]£15[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]22/11/17[/TD]
[TD]£20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]07/03/17[/TD]
[TD]£25[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]13/04/17[/TD]
[TD]£40[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]04/05/17[/TD]
[TD]£50[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]25/05/17[/TD]
[TD]£60[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #FAFAFA"]Bob[/TD]
[TD="bgcolor: #FAFAFA"]15/06/17[/TD]
[TD="bgcolor: #FAFAFA"]£70[/TD]
[TD="bgcolor: #FAFAFA"][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
The formula i provided doesnt care if you dont have dates every week. All it is doing is providing the last *date* that has the name paul and is before the 6/9/2017 + 5 weeks.

Edit. * Pay not date!
 
Last edited:
Upvote 0
Yeah, I can see that. Again, due to my poor example and the way I had been working it out, it wouldn't be weeks at all. So it would need to look for 5 rows down (changed to Max Payments rather than max weeks in the example), but stop at the last instance of Paul
 
Upvote 0
Could you try to explain in words what you want? The last instance of paul?
 
Upvote 0
Basically, 5 rows down from Paul 06/09/17...but stop at the last instance of Paul if this is less than 5 rows down. I've changed the examples below that hopefully makes it a bit clearer. on the left, the formula {=OFFSET(INDEX(C5:C21,MATCH(A2&B2,A5:A21&B5:B21,0)),C2,0)} works because there are enough instances of "Paul". However, if I change the Start Week as shown in the example on the right, it returns a value attributed to Bob.

Problem.V1.JPG
 
Upvote 0
This array formula appears to do the job. It must be entered CTRL-SHIFT-ENTER.

=IFERROR(INDEX(C5:C21,SMALL(IF((A5:A21=A2)*(B5:B21>=B2),(ROW(A5:A21)-ROW(A4))),C2)),LOOKUP(2,1/(A5:A21=A2),C5:C21))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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