Find Difference Of Prices For Each Day

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a 4 columns: Date(itemA), Price(itemA), Date(itemB), Price(itemB).
I need to find the difference of Price(itemA) and Price(itemB) for each day.
However, there are more data/date on itemB than itemA.

So I can't use a simple formula of (=B2-D2). Since date for B2 may not be the same date for D2.

I wonder how could I structure my formula, perhaps using "if" and "vlookup"
to find the difference of Price of the 2 items for each day.

Thank you!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Excel Workbook
ABCDE
1Date (Item A)Price (Item A)Date (Item B)Price (Item B)Difference
21/1/2011371/1/2011235
31/3/2011701/2/201149-49
41/4/2011371/3/20113337
51/5/2011781/4/20112611
61/6/2011581/5/2011573
71/8/2011931/6/201199-41
81/9/2011701/7/201178-78
91/10/2011101/8/20117518
101/11/2011481/9/20115812
111/12/2011261/10/201123-13
121/19/2011751/11/20112919
131/20/2011171/12/201197-71
141/21/2011891/13/201121-21
151/22/2011881/14/201135-35
161/23/2011951/15/201189-89
171/28/2011581/16/201190-90
18**1/17/201164-64
19**1/18/201132-32
20**1/19/2011705
21**1/20/201186-69
22**1/21/20112267
23**1/22/20117414
24**1/23/20112174
25**1/24/201154-54
26**1/25/20119-9
27**1/26/201158-58
28**1/27/20118-8
29**1/28/201187-29
Sheet1
 
Last edited:
Upvote 0
Hi,

Thank you for your help!!

I wonder if I could return null or just return nothing, if there is no matching date?
 
Upvote 0
Sorry, think I know how to do this....
Let me try the formula....
Thank you!
 
Upvote 0
IF(ISERROR(VLOOKUP(C2,$A$2:$B$17,2,FALSE))=TRUE,0,VLOOKUP(C2,$A$2:$B$17,2,FALSE)-D2)

will return zero,

IF(ISERROR(VLOOKUP(C2,$A$2:$B$17,2,FALSE))=TRUE,"Null",VLOOKUP(C2,$A$2:$B$17,2,FALSE)-D2)

will return the word "null"

You could also change the "Null" to just "" and it will be blank, but be careful, excel will treat it as a zero length string and not a true blank nor zero (this has caused problems for me in the past)
 
Upvote 0
IF(ISERROR(VLOOKUP(C2,$A$2:$B$17,2,FALSE))=TRUE,0,VLOOKUP(C2,$A$2:$B$17,2,FALSE)-D2)

will return zero,

IF(ISERROR(VLOOKUP(C2,$A$2:$B$17,2,FALSE))=TRUE,"Null",VLOOKUP(C2,$A$2:$B$17,2,FALSE)-D2)

will return the word "null"

You could also change the "Null" to just "" and it will be blank, but be careful, excel will treat it as a zero length string and not a true blank nor zero (this has caused problems for me in the past)
You don't need to test that ISERROR() = TRUE. It returns either TRUE or FALSE so a test for one of those conditions would be redundant.

Also, you can save a couple of keystrokes by using 0 instead of FALSE for the range_lookup argument.

IF(ISERROR(VLOOKUP(C2,$A$2:$B$17,2,0)),"Null",VLOOKUP(C2,$A$2:$B$17,2,0)-D2)

If they happen to be using Excel 2007 or later:

=IFERROR(VLOOKUP(C2,$A$2:$B$17,2,0)-D2,"Null")
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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