Values corresponding to the closest date match

Suza2007

New Member
Joined
Jun 21, 2018
Messages
4
Hi All,

I have the following raw data:

[TABLE="width: 479"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD][/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Material
[/TD]
[TD]Bill Date
[/TD]
[TD]Unit Price
[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]14/05/2018
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]03/05/2018
[/TD]
[TD]323
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]10/05/2018
[/TD]
[TD]300
[/TD]
[TD][/TD]
[TD]Material
[/TD]
[TD]Unit Price
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]28/05/2018
[/TD]
[TD]300
[/TD]
[TD][/TD]
[TD]A
[/TD]
[TD]323
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]02/06/2018
[/TD]
[TD]278
[/TD]
[TD][/TD]
[TD]C
[/TD]
[TD]1050
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]16/06/2018
[/TD]
[TD]210
[/TD]
[TD][/TD]
[TD]R
[/TD]
[TD]500
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]21/12/2017
[/TD]
[TD]1050
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]22/12/2017
[/TD]
[TD]1050
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]27/12/2017
[/TD]
[TD]1050
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]29/01/2018
[/TD]
[TD]900
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]29/01/2018
[/TD]
[TD]900
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]29/03/2018
[/TD]
[TD]500
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]16/04/2018
[/TD]
[TD]490
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]19/04/2018
[/TD]
[TD]490
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]22/05/2018
[/TD]
[TD]470
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]25/05/2018
[/TD]
[TD]470
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]15/06/2018
[/TD]
[TD]450
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]20/06/2018
[/TD]
[TD]450
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]R
[/TD]
[TD]21/06/2018
[/TD]
[TD]450
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Am trying to create a report as on 14th May 2018 where I need unit price corresponding to the nearest date.
Hence for “A” I must get unit price as 300 & “C” as 900 as that is last latest date (29/01/2018) & “R” as 490.

Am using “=IFERROR(VLOOKUP(F5,B2:D20,3,0), INDEX(C3:C20,MATCH(G2,D3:D20,-1)+1))”, however it gives me the very first value(unit price) for each material.

Any help is much appreciated.

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This?


Excel 2010
ABCDEFG
1MaterialBill DateUnit Price5/14/2018
2A5/3/2018323
3A5/10/2018300MaterialUnit Price
4A5/28/2018300A300
5A6/2/2018278C900
6A6/16/2018210R490
7C12/21/20171050
8C12/22/20171050
9C12/27/20171050
10C1/29/2018900
11C1/29/2018900
12R3/29/2018500
13R4/16/2018490
14R4/19/2018490
15R5/22/2018470
16R5/25/2018470
17R6/15/2018450
18R6/20/2018450
19R6/21/2018450
Sheet13
Cell Formulas
RangeFormula
F4{=VLOOKUP($F$1,IF($A$2:$A$19=E4,$B$2:$C$19),2,1)}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
Amazing. Thank you so much for the help.

just one quick question, after entering the formula in cell "F4" when i double clicked it was giving me #N/A error.
 
Upvote 0
This formula isnt working for me on F5 & F6 cells though i tried entering it manually instead of copy paste. please help
 
Upvote 0
What I said about holding down ctrl-shift with the enter doesn't apply when you drag the formula or copy and paste, only if you actually enter it (either for the first time or after double clicking/pressing F2 etc)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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