Calculate Number of Days Between Orders of Same Item

mcmuney

Board Regular
Joined
Sep 11, 2015
Messages
97
Office Version
  1. 365
Hello, the below is a scenario for ordering items and I'm looking to calculate the number of days between each for each item. Once I have the days, I can't seem to figure out how to calculate this.

Any help would be greatly appreciated. Red font would be the expected results.

Thanks!

Order Date (colA)Item (colB)# Ordered (ColC)Days Between Orders of Same Item
10/1/23A15n/a since it's the first item
10/6/23A125 days (A3-A2)
10/7/23B13n/a since it's a new item
10/15/23A119 days (A5-A3)
10/25/23A1410 days (A6-A5)
10/26/23C12n/a since it's a new item
10/27/23B1120 days (A8-A4)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this:

Book1
ABCDE
1Order Date (colA)Item (colB)# Ordered (ColC)Days Between Orders of Same Item
210/1/2023A15 n/a since it's the first item
310/6/2023A1255 days (A3-A2)
410/7/2023B13 n/a since it's a new item
510/15/2023A1199 days (A5-A3)
610/25/2023A141010 days (A6-A5)
710/26/2023C12 n/a since it's a new item
810/27/2023B112020 days (A8-A4)
Sheet1
Cell Formulas
RangeFormula
D2:D8D2=IFERROR(A2-LOOKUP(2,1/($B$1:B1=B2),$A$1:A1),"")
 
Upvote 0
With Excel 365 you could also use this
Excel Formula:
=IFNA(A2-XLOOKUP(B2,B$1:B1,A$1:A1,,,-1),"")
 
Upvote 0
Thank you Peter! Both formulas work, but I can't determine if one is more efficient than the other :unsure:
 
Upvote 0
You're welcome. :)

I can't determine if one is more efficient than the other
If the data is small you wouldn't notice the difference. However, as the data size grows, XLOOKUP gets relatively faster, I think due mainly to the slowness of all the division calculations in the LOOKUP formula.
I just did a test with 5,000 rows of data. To calculate the 5,000 results ..
XLOOKUP: 0.066 seconds
LOOKUP: 0.98 seconds

So a time difference factor of about 15x for this size data (on my machine)
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,995
Members
449,094
Latest member
masterms

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