Min of 5 cells before different from 0

rama1234

New Member
Joined
Apr 25, 2016
Messages
5
Hello everyone, thanks for your time in advance.
My first column are numbers, for example:
A1: Column 1
A2: 10
A3: 2
A4: 10
A5: 10
A6: 5
A7: 0
A8: 0
A9: 0
A10: 5
A11: 5
A12: 5
...
Then in my second column calculates the minimum of 5 cells before that are different from 0.
For example the cell B6 is the minimum of A6-A5-A4-A3-A2 different from 0, so is 2... But the cell B9 is also the minimum of A6-A5-A4-A3-A2 as I want the minimum of 5 numbers that are different from 0 and I don't know how to do it.
My formula in B9 is:
{=IF(ROW(A9)<=5;0;MIN(IF((INDEX(A:A;ROW(A10)-5):A9)<>0;(INDEX(A:A;ROW(A10)-5):A9))))}

My desired results in column 2 are:
B1: Column 2
B2: 0
B3: 0
B4: 0
B5: 0
B6: 2
B7: 2
B9: 2
B10: 2
B11: 5
B12: 5

Thanks a lot
 

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.
Hi, here is one option you can try.


Excel 2013/2016
AB
2100
320
4100
5100
652
702
802
902
1052
1155
1255
Sheet1
Cell Formulas
RangeFormula
B2{=IF(COUNTIFS(A$2:A2,"<>0")<5,0,MIN(IF(ISNUMBER(MATCH(ROW(A$2:A2),LARGE(IF(A$2:A2<>0,ROW(A$2:A2)),{1,2,3,4,5}),0)),A$2:A2)))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Hi

Another option, also array formula:

=IFERROR(MIN(IF(ROW($A$2:A2)>=LARGE(IF(A$2:A2<>0,ROW(A$2:A2)),5),IF($A$2:A2>0,$A$2:A2))),0)
 
Upvote 0
Thanks, it outputs the desired results but I want to use the minimum of 5 days as variable so I can change it to say 10, 20, 50... Maybe you know how to do it,
Thanks
 
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,778
Members
453,371
Latest member
HMX180

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