how do I average the lowest 3 of the final 6 numbers in a row of 22? Some cells may be blank

How do I automatically average the lowest 3 of the last 6 numbers in a row of 22 that adds one number per week? Obviously I need at least 7 numbers to begin using this formula. Also, some cells in some rows may be blank.


Use a helper column with this formula

=IF(A2,ROW(),0)

Copy down.

Then use this array formula, confirmed with Ctrl - Shift - Enter

=AVERAGE(SMALL(IF((A2:A15<>0)*(B2:B15=LARGE(B2:B15,{1,2,3,4,5,6})),A2:A15),{1,2,3}))

enter image description here

The Large function pins down the six largest numbers in column B. The If function returns the respective numbers in column A. The Small function returns the three smallest from that set. And Average does the average of these.

That's how it works in Excel. Not sure about LibreOffice Calc.

Edit: here is a variant that works without a helper column:

=AVERAGE(SMALL(IF((A2:A15<>0)*(IF(ISNUMBER(A2:A15),ROW(A2:A15))=LARGE(IF(ISNUMBER(A2:A15),ROW(A2:A15)),{1,2,3,4,5,6})),A2:A15),{1,2,3}))

Also confirmed with Ctrl - Shift - Enter


One way to do this would be to use the "small" function. I'm not sure if you can return the lowest three values altogether, but you could use three different cells with varying "ranks" of "small" and then take the average of those together:

[Let's say you have a column of numerical data B3:B80...]
[Sample data from B column: 19, 23, 23, 24, 24, 27, 27, 27, 28, 29, 29, 29...]

[cell on left, cell contents in quotes, output on right of =>]

   C3 '=SMALL(B3:B80;3)' => 23 (third lowest number)
   C4 '=SMALL(B3:B80;2)' => 23 (second lowest number)
   C5 '=SMALL(B3:B80;1)' => 19 (first lowest number; you could also used "MIN")
   C6 '=AVERAGE(C3:C5)' => 21.67