且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

平均行总数而不在Excel中创建新列

更新时间:2023-12-03 20:09:10

您可以使用数组公式更简洁地完成此操作,但是解决现有公式的简短答案是,如果工作表中的某个位置有空白单元格(假设是F1)AVERAGE将忽略空白单元格,因此将公式更改为

You can do this more concisely with an array formula, but the short answer to fix up your existing formula is, if you have a blank cell in your sheet somewhere (say it's F1) AVERAGE will ignore blank cells so change your formula to

=AVERAGE(IF(AND(A1<>"",B1<>"",C1<>"",D1<>"",E1<>""),SUM(A1:E1),F1),IF(AND(A2<>"",B2<>"",C2<>"",D2<>"",E2<>""),SUM(A2:E2),F1),IF(AND(A3<>"",B3<>"",C3<>"",D3<>"",E3<>""),SUM(A3:E3),F1),IF(AND(A4<>"",B4<>"",C4<>"",D4<>"",E4<>""),SUM(A4:E4),F1),IF(AND(A5<>"",B5<>"",C5<>"",D5<>"",E5<>""),SUM(A5:E5),F1))

这将是您公式的一个数组公式版本-它使用OFFSET拉出矩阵的每一行,然后使用SUBTOTAL来查看该行中的每个单元格中是否都有数字.然后再次使用SUBTOTAL求出每行的总和,并使用AVERAGE求出行的平均值.

This would be one array formula version of your formula - it uses OFFSET to pull out each row of the matrix then SUBTOTAL to see if every cell in that row has a number in it. Then it uses SUBTOTAL again to work out the sum of each row and AVERAGE to get the average of rows.

=AVERAGE(IF(SUBTOTAL(2,OFFSET(A1,ROW(A1:A5)-ROW(A1),0,1,COLUMNS(A1:E1)))=COLUMNS(A1:E1),SUBTOTAL(9,OFFSET(A1,ROW(A1:A5)-ROW(A1),0,1,COLUMNS(A1:E1))),""))

必须使用 Ctrl Shift Enter

注1-有些人不喜欢使用OFFSET,因为它易变-您可以改用矩阵乘法,但是它不那么容易理解.

Note 1 - some people don't like using OFFSET because it is volatile - you can use matrix multiplication instead but it's arguably less easy to understand.

注2-我使用"代替了一个空单元格.有趣的是,非数组公式需要一个实际的空白单元格,但数组公式需要一个空字符串.

Note 2 - I used "" instead of referring to an empty cell. Interesting that the non-array formula needed an actual blank cell but the array formula needed an empty string.

您可以省略空字符串

=AVERAGE(IF(SUBTOTAL(2,OFFSET(A1,ROW(A1:A5)-ROW(A1),0,1,COLUMNS(A1:E1)))=COLUMNS(A1:E1),SUBTOTAL(9,OFFSET(A1,ROW(A1:A5)-ROW(A1),0,1,COLUMNS(A1:E1)))))