我只需要在电子表格上返回某个类别的中位数。下面的例子
Airline 5
Auto 20
Auto 3
Bike 12
Airline 12
Airline 39
等等。
如何编写公式以仅返回航空公司类别的中值。类似于 Average if,仅适用于中位数。我无法重新排列这些值。谢谢!
我只需要在电子表格上返回某个类别的中位数。下面的例子
Airline 5
Auto 20
Auto 3
Bike 12
Airline 12
Airline 39
等等。
如何编写公式以仅返回航空公司类别的中值。类似于 Average if,仅适用于中位数。我无法重新排列这些值。谢谢!
Assuming your categories are in cells A1:A6 and the corresponding values are in B1:B6, you might try typing the formula =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,""))
in another cell and then pressing CTRL+SHIFT+ENTER
.
Using CTRL+SHIFT+ENTER
tells Excel to treat the formula as an "array formula". In this example, that means that the IF
statement returns an array of 6 values (one of each of the cells in the range $A$1:$A$6
) instead of a single value. The MEDIAN
function then returns the median of these values. See http://www.cpearson.com/excel/arrayformulas.aspx for a similar example using AVERAGE
instead of MEDIAN
.
Make a third column that has values like:
=IF(A1="Airline",B1)
=IF(A2="Airline",B2) etc
Then just perform a median on the new column.
扩展 Brian Camire 的答案:
使用=MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,""))
withCTRL+SHIFT+ENTER
将在计算中包含空白单元格。空白单元格将被评估为 0,这会导致中值较低。如果使用平均函数也是如此。如果您不想在计算中包含空白单元格,请使用嵌套 if 语句,如下所示:
=MEDIAN(IF($A$1:$A$6="Airline",IF($B$1:$B$6<>"",$B$1:$B$6)))
不要忘记按CTRL+SHIFT+ENTER
将公式视为“数组公式”。
一种解决方案可能是找到一种方法从字符串中提取数字并将它们放在仅包含数字的列中,使用 =MEDIAN() 函数将新数字列作为范围