Need to find first and last occurrences in multiple columns to reference adjacent fields

mwjessica

New Member
Joined
Jul 18, 2011
Messages
3
Hi All,

I hope someone can help me. I have an Excel spreadsheet that contains records of shipments. Columns include: Order Date, Part Number 1, Part Number 2, Part Number 3, etc.

This is what I'm trying to do: For each Part Number column, I need to automatically find the first and last values, and reference the adjacent Order Dates. A lot of the cells in the Part Number columns are blank, thus my need to find first and last Order Dates based on the first and last occurrence of values in each column. Then I'd like to take those dates and plug them into a simple formula (one formula per column, probably residing above the heading) to calculate the number of months of shipment history.

Currently, I'm using a formula to simply calculate the number of months of ALL order history (see below). But this isn't an accurate number for most part numbers, as different parts started getting ordered on different dates.

MonthsOfHistory = (MAX(ShipmentHistory[Order Date]) - MIN(ShipmentHistory[Order Date])) / 30
AvgMonthlyUsage = ShipmentHistory[[#Totals],[Part_Number_1]] / MonthsOfHistory

What I'm trying to do with this information is calculate average monthly usage per Part Number. Using my crappy, generic formula above gives me numbers that are too low.

I hope this makes sense. Any help or suggestions would be greatly appreciated.

-Jessica
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Excel Workbook
ABCDEFGHI
1Part No.Most recentEarliestdifference
2DD37328-Mar-1116-Jan-112 months 12 days
3Order DatePart No. 1Part No. 2Part No. 3DD60412-Mar-1116-Dec-102 months 24 days
419-Jul-11DD591DD611DD233DD77812-Mar-1102-Nov-104 months 10 days
512-Mar-11DD778DD392DD604DD18511-Dec-1011-Dec-100 months 0 days
607-Mar-11DD624DD373DD209DD19220-Dec-1020-Dec-100 months 0 days
716-Jan-11DD373DD208DD778DD20816-Jan-1116-Jan-110 months 0 days
828-Mar-11DD781DD626DD373DD20907-Mar-1107-Mar-110 months 0 days
906-Jan-11DD936DD581DD268
1004-Feb-11DD778DD388DD847
1110-Oct-10DD354DD906DD272
1216-Dec-10DD604DD746DD244
1322-Nov-10DD959DD778DD515
1403-Apr-11DD948DD562DD973
1509-Dec-10DD183DD122DD700
1602-Nov-10DD778DD953DD653
1714-Jan-11DD107DD581DD402
1828-Nov-10DD634DD288DD915
1920-Dec-10DD192DD603DD778
2003-Mar-11DD438DD604DD508
2111-Dec-10DD185DD819DD920
Sheet3


Formulae in cells G2 and H2 are ARRAY-ENTERED using Ctrl + Shift + Enter, and copied down.
It doesn't find lowest/highst row numbers, it finds max and min dates, which I think is what you want.
Formula in cell I2 is normally-entered, in which I've used a non-documented excel function.

Dates don't need to be sorted.
I've highlighted part nos. which repeat.

I haven't understood what you want by Average Monthly Usage, but hopefully I've given you enough to get started?
 
Upvote 0
Hi p45cal,

Thanks very much for your response. Here is a picture to hopefully clarify my intentions.

mo_of_hist.jpg


The part that I get stuck on is calculating the "Months of Order History" automatically. For instance: For part number A100, the months of order history should be 02/18/11 minus 09/07/10 divided by 30. So, can I pull the two dates based on the first and last occurrences of quantities (4 and 2) in column D?

Thank you for your help!

-Jessica
 
Upvote 0
Ah, an Excel Jeanie shot, or screenshot or picture always helps.
Excel Workbook
ABCDEF
1Order dateOrder typeorder #PN# A100PN# A200PN# A300
210-Oct-10CUSTOMERS10311
307-Sep-10CUSTOMERS1054
423-Oct-10CUSTOMERS1061010
504-Nov-10CUSTOMERS111
615-Dec-10CUSTOMERS1141212
701-Jan-11CUSTOMERS11712
818-Feb-11CUSTOMERS119264
931-Mar-11CUSTOMERS12024
10Total Qty185237
11Earliest date07-Sep-1023-Oct-1010-Oct-10
12Most recent date18-Feb-1131-Mar-1118-Feb-11
13Months of Order History5 months 11 days5 months 8 days4 months 8 days
14Avg Monthly Qty3.39.88.5
Sheet


Formule in D11 and D12 need to be ARRAY-ENTERED (individually) as described before, D13 and D14 should be entered normally, then you can copy to the right.
Again, the dates need not be sorted, max and min dates are taken.

D13 can be shortened to give just month numbers:
=DATEDIF(D$11,D$12,"m")
It rounds down.
Then D14 can be:
=D$10/D$17
but remember the calculation uses the rounded down no. of months.
 
Upvote 0
A small tweak to cope with missing dates:
Excel Workbook
D
1107-Sep-10
1201-Jan-11
Sheet3


when the latest/earliest valid date will be taken instead.

If you use the suggestion of dividing by the rounded down no. of months for the average monthly quantity, occasionally this will lead to division by zero errors when the time between first and last orders is less than a month.
 
Upvote 0
Hi p45cal,

This worked! This is what I did:

Earliest Date (D2):
{=MIN(IF(ISNUMBER(D$7:D140),$A$7:$A140))}
Latest Date (D3): {=MAX(IF(ISNUMBER(D$7:D140),$A$7:$A140))}
Months of History (D4): =(D3-D2)/30
Monthly Average (D5): =IF(D4>0,ROUND(ShipmentHistory[[#Totals],[A100]]/D4,0),"")

Thank you so much! I don't have experience with arrays, so I couldn't have done this without you! :)

-Jessica
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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