Reputation: 265
Hi, I have a list of payments and a table with the promises that collection officers made.
I want assign into the payment table by id (and date) the last collection officer that made the agreement with the debtor.
For example: On id 1111 there were two promises made: by Morticia Adams and Gulliver; But i choose Gulliver because he made the last promise in that date range taking in account the date of payment.
Likewise for id 5425 the last promise made was made by Marie Anne because 23.10.2016 (date of payment) is between 12.10.2016 and 26.10.2016 (promise dates).
I would be really grateful if somebody could guide me through this.
Thanks you!
Upvotes: 0
Views: 88
Reputation: 10776
One way to do this is by finding the latest conversation date that satisfies the conditions:
Which we can do like this:
{=MAX(($A$3:$A$8 = A12) * (B12 >= $B$3:$B$8) * (B12 <= $C$3:$C$8) * $B$3:$B$8)}
And then combining the date with the payment ID to have a unique key that we can use to look up the name.
{=MAX(($A$3:$A$8 = A12) * (B12 >= $B$3:$B$8) * (B12 <= $C$3:$C$8) * $B$3:$B$8) & A12}
And lastly we can perform an Index match, looking up the output of the above formula in the concatenated range of date and payment ID in the promises table
{=INDEX(
$D$3:$D$8,
MATCH(
MAX(($A$3:$A$8 = A14) * (B14 >= $B$3:$B$8) * (B14 <= $C$3:$C$8) * $B$3:$B$8) & A14,
$B$3:$B$8 & $A$3:$A$8,
0))}
The {}
means you have to enter the formula using Ctrl + Shift + Enter
Note that this will be a lot more readable and intuitive if you name the ranges.
Upvotes: 1