Formula to lookup text and return when it first and last shows a value in the next column

kthof

New Member
Joined
Nov 6, 2015
Messages
3
Below is an example of the data that I'm trying to analyse and I need 2 formulas to look up a style code and find the week when it was first stocked (i.e. the inventory column first showed a value for that code) and the week it went out of stock (i.e. the inventory was 0). A couple points to note, I can't look for the first occurrence of the style code as the data shows several weeks with 0 inventory in the first few weeks. Also the inventory may go to 0 several times over the time period, I want to find the last time it went to 0.

The answers I'd be looking for in the below example is:
Style A1234 came into stock in week 2 and went out of stock in week 4.
Style B2345 came into stock in week 3 and went out of stock in week 5.

Style CodeWeekInventory
A12341
A12342200
A12343100
A12344
A12345
B23451
B23452
B2345350
B2345410
B23455

<tbody>
</tbody>

Can anyone help please??
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Re: Help with a formula to lookup text and return when it first and last shows a value in the next column

Try:

ABCDEFG
1Style CodeWeekInventoryStyle CodeCame into stockWent out of stock
2A12341A123424
3A12342200B234535
4A12343100
5A12344
6A12345
7B23451
8B23452
9B2345350
10B2345410
11B23455

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Array Formulas
CellFormula
F2{=INDEX($B$2:$B$11,MATCH(1,IF(($A$2:$A$11=E2)*($C$2:$C$11>0),1,0),0))}
G2{=INDEX($B$2:$B$11,SMALL(IF(($A$2:$A$11=E2)*($C$2:$C$11=0)*(ROW($A$2:$A$11)>=LOOKUP(2,1/(($A$2:$A$11=E2)*($C$2:$C$11>0)),ROW($A$2:$A$11))),ROW($A$2:$A$11)-ROW($A$2)+1),1))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
Re: Help with a formula to lookup text and return when it first and last shows a value in the next column

Thank you Eric, that worked perfectly :)
 
Upvote 0
Re: Help with a formula to lookup text and return when it first and last shows a value in the next column

Another option,

1] Using Eric's table layout in post #.2

2] In F2, non-array formula copied right to G2 and all copied down :

=INDEX($B$2:$B$11,AGGREGATE(14+(LEFT(F$1)="C"),6,ROW($B$2:$B$11)-ROW($B$1)/($A$2:$A$11=$E2)/($C$2:$C$11<>""),1)+(LEFT(F$1)="W"))

Regards
Bosco
 
Upvote 0
Re: Help with a formula to lookup text and return when it first and last shows a value in the next column

..Or give this a try:

Excel Workbook
ABCDEFG
1Style CodeWeekInventoryStyle CodeInOut
2A12341A123424
3A12342200B234535
4A12343100
5A12344
6A12345
7B23451
8B23452
9B2345350
10B2345410
11B23455
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,639
Members
449,111
Latest member
ghennedy

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