Find MIN within a range & count how many consecutive negative numbers until the MIN

kylc3

New Member
Joined
Jun 16, 2017
Messages
14
Let's say I have a column with the following values:

...
-0.26%
-0.09%
0.00%
0.00%
-0.25%
-0.82%
-1.08%
-1.09%
-0.98%
-1.27%
-1.04%
-1.78%
-3.46%

-2.80%
0.00%
-1.39%
...

Is there a formula that can:

Identify the MIN (-3.46%), then c
ount the # of consecutive negative #s from above the MIN until it reaches it (including the MIN). In this example, I'd like the result of the formula to be 9.

Hopefully this request makes sense. Thanks in advance!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the forum.

Try:

ABC
1Values
2-0.26%
3-0.09%9
40.00%
50.00%
6-0.25%
7-0.82%
8-1.08%
9-1.09%
10-0.98%
11-1.27%
12-1.04%
13-1.78%
14-3.46%
15-2.80%
160.00%
17-1.39%

<tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
C3{=MATCH(MIN(A2:A17),A2:A17,0)-LARGE(IF((A2:A17>=0)*(ROW(A2:A17)-ROW(A2)+1< MATCH(MIN(A2:A17),A2:A17,0)),ROW(A2:A17)-ROW(A2)+1),1)}

<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>
 
Last edited:
Upvote 0
Welcome to the forum. I think I concocted something that works. Note that in cases where the minimum value exists more than once in the DATA, the formula will act on only the first occurrence.

AB
1DATA
2-0.26%
3-0.09%
40.00%
50.00%
6-0.25%
7-0.82%
8-1.08%
9-1.09%
10-0.98%
11-1.27%
12-1.04%
13-1.78%
14-3.46%
15-2.80%
160.00%
17-1.39%
18Streak of negatives before Minimum
199

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

Array Formulas
CellFormula
B19{=IF(INDEX(A2:A17,MATCH(MIN(A2:A17),A2:A17,0)-1)>=0,0,MAX(FREQUENCY(IF(OFFSET(A2,,,MATCH(MIN(A2:A17),A2:A17,0))<0,ROW(OFFSET(A2,,,MATCH(MIN(A2:A17),A2:A17,0)))),IF(OFFSET(A2,,,MATCH(MIN(A2:A17),A2:A17,0))>=0,ROW(OFFSET(A2,,,MATCH(MIN(A2:A17),A2:A17,0)))))))}

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

<tbody>
</tbody>
 
Upvote 0
Eric, I think this formula reports an incorrect result when the number prior to the MIN value is not a negative. For example, change A14 to 0. The MIN value would then be -2.80% and the value above it would be zero, so the formula should report 0 and not 1 as it does.
 
Upvote 0
Eric, I think this formula reports an incorrect result when the number prior to the MIN value is not a negative. For example, change A14 to 0. The MIN value would then be -2.80% and the value above it would be zero, so the formula should report 0 and not 1 as it does.

I think it should return 1 - see below in bold

Identify the MIN (-3.46%), then c
ount the # of consecutive negative #s from above the MIN until it reaches it (including the MIN). In this example, I'd like the result of the formula to be 9.

Maybe this regular formula also works.
=MATCH(MIN(A2:A17),A2:A17,0)-LOOKUP(2,1/(A2:INDEX(A2:A17,MATCH(MIN(A2:A17),A2:A17,0))>=0),ROW(A2:A17)-ROW(A2)+1)

M.
 
Upvote 0
Another way (easier for people like me) would be to type this formula in B1 (assuming your data starts in A1). This will require you to create a new column...FYI

=IF(A1<0,1,0)

Then, in B2 (under the above formula) type this formula and copy down:

=IF(A2<0,B1+1,0)

After this step, put this function where you would like the output to be:

=MAX(A:A)


To find the minimum, you can simply use the MIN function:

=MIN(A:A)

Hope this helps.
 
Upvote 0
@DRSteele:

You may be right. However, the example from the OP gave a result of 9. This means that the minimum value was included in the count, otherwise the expected result would have been 8. So I designed the formula to give a minimum value of 1 (or #NUM if there are no negative values). We may need clarification from the OP.

@Marcelo: Clever formula!
 
Last edited:
Upvote 0
Wow, that was fast! Thank you all for the feedback! I applied DRSteele's formula and it worked great! I need to build out some more functionality in the file, but first I'll have to figure out what the heck I need it to output. It's awesome to know I can reach out to this great forum when I inevitably get stuck. Thx again!
 
Upvote 0
@DRSteele:

You may be right. However, the example from the OP gave a result of 9. This means that the minimum value was included in the count, otherwise the expected result would have been 8. So I designed the formula to give a minimum value of 1 (or #NUM if there are no negative values). We may need clarification from the OP.

@Marcelo: Clever formula!

@Eric
Thank you

If there are no negative values, my formula returns 0 - it seems Ok for me, unless OP thinks differently ;)

M.
 
Upvote 0
oops...it seems that no suggested formula works if the min is first value (A2 in this case)

So i've adjusted my formula (post #5) to
=MATCH(MIN(A2:A17),A2:A17,0)-IFERROR(LOOKUP(2,1/(A2:INDEX(A2:A17,MATCH(MIN(A2:A17),A2:A17,0))>=0),ROW(A2:A17)-ROW(A2)+1),0)

M.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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