Excel:平均如果

发布于 2024-10-22 13:47:02 字数 86 浏览 3 评论 0原文

假设我有一个 Excel 工作表,其中:

第 1 列包含工资
第 2 栏包含性别(男/女)

我如何计算女性的平均工资?

Lets say I have an Excel sheet such that:

Column 1 contains salaries
Column 2 contains gender (M/F)

How can I calculate the average salary for females?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

森末i 2024-10-29 13:47:02
=AVERAGE(IF(B1:B10="F",A1:A10))

作为数组函数输入(即使用 Shift-CTRL-Enter 而不仅仅是 Enter)

=AVERAGE(IF(B1:B10="F",A1:A10))

entered as an array function (ie using Shift-CTRL-Enter rather than just Enter)

英雄似剑 2024-10-29 13:47:02

尽管答案已经被回答/接受,但我还是忍不住添加我的 2 美分:

总和和平均值通常显示在列表的底部。您可以使用 SUBTOTAL() 函数计算总和和平均值,并指定包括或排除“隐藏”值,即由过滤器抑制的值。因此,解决方案可能是:

  • 为平均值创建一个公式 =SUBTOTAL(101,A2:A6)
  • 为总和创建一个公式 =SUBTOTAL(109,A2:A6)
  • 在“性别”列上创建自动筛选器

现在,当您筛选“F”、“M”或全部时,将始终计算正确的总和和平均值。

希望有帮助 - 祝你好运

Allthough the answer is already answered/accepted I can't resist to add my 2 cents:

Sums and averages normally are displayed at the bottom of a list. You can use the SUBTOTAL() function to calculate sum and average and specify to include or exclude "hidden" values, i.e. values suppressed by a filter. So the solution could be:

  • create a formula =SUBTOTAL(101,A2:A6) for the average
  • create a formula =SUBTOTAL(109,A2:A6) for the sum
  • create an autofilter on the Gender column

Now, when you filter for "F", "M" or all, the correct sum and average will always be computed.

Hope that helps - Good luck

清秋悲枫 2024-10-29 13:47:02

要在没有数组公式的情况下执行此操作,只需使用以下命令:

=SUMIF(B:B,"F",A:A)/COUNTIF(B:B,"F")

To do it without an array formula just use this:

=SUMIF(B:B,"F",A:A)/COUNTIF(B:B,"F")
苏别ゝ 2024-10-29 13:47:02

已回答的问题,可靠的公式 - 但是 - 请注意基于数字的条件平均值:

在非常相似的情况下,我尝试过:

“=AVERAGE(IF(F696:F824<0;E696:E824))”(移位控制输入) - 在英语中,如果 F 列中的结果为负(损失),则要求 Excel 计算 E 列中所有数字的平均值 - 例如“计算发生损失的所有项目的平均值”。 (无循环引用)

当要求计算发生增益 (x>0) 的所有项目的平均值时,Excel 是正确的。然而,当条件平均值基于损失时,Excel 产生了巨大的错误(7.53 而不是 28.27)。

然后,我在 Open Office 中打开完全相同同一个文档,Calc 从同一个数组公式中得到了(正确)答案 28,27。

在 Excel 中分步骤重新计算整个过程(第一个新列仅包含损失,新列仅包含增益,新列仅包含发生损失/增益的 E 值,然后进行“干净”(无条件)平均计算,生成正确的值 因此,

应该注意的是,在某些条件平均值的情况下,Excel 和 Open Office 会产生不同的答案(Excel 2007(瑞典语版本)会出错)

(抱歉,我的警告性故事很长,但在计算结果时要小心一点) 。条件是一个数字是我的建议)

Answered question, solid formulas - BUT - beware of conditional averages based on numbers:

In a very similar situation I tried:

"=AVERAGE(IF(F696:F824<0;E696:E824))" (shift control enter) - In English this asked Excel to calculate an average on all numbers in column E if a result in column F was negative (a loss) - e.g. "calculate an average for all items where a loss occured". (no circular reference)

When asked to calculate an average for all items where a gain (x>0) occured, Excel got it right. However, when the conditional average was based on a loss - Excel produced a huge error (7.53 instead of 28.27).

I then opened exactly the same document in Open Office, where Calc got the (correct) answer 28,27 from the same Array formula.

Recalculating the whole thing in steps in Excel (first new column of only losses, new for only gains, new column for only E-values where a loss/gain occured, then a "clean" (unconditional) average calculation, produced the correct values.

Thus, it should be noted that Excel and Open Office produce different answers (and Excel 2007, Swedish language version, gets them wrong) in some cases of conditional averages.

(sorry for my long cautionary tale - but be a bit careful when the condition is a number would be my advice)

花海 2024-10-29 13:47:02

您可以将过滤器放在工作表的顶行。然后从 Column2 中仅过滤 F,然后计算值的平均值。

You can put filter in top line of your sheet. Then Filter only Fs from Column2, then calculate average of values.

原谅我要高飞 2024-10-29 13:47:02

或者您可以添加仅包含女性工资的附加列。

公式如下: =IF(B1 = "Female";A1)

然后您只需计算新创建列的平均值。

Or you can add additional column with female salaries only.

The formula would be like: =IF(B1 = "Female";A1)

Then you simply calculate average of newly created column.

假情假意假温柔 2024-10-29 13:47:02

薪资性别
2500米0 2500*0
2400 F 1 2400×1
2300 F 1 2300×1
sum =2 sum=4700average=4700/2

也许很复杂。

Salaries gender
2500 M 0 2500*0
2400 F 1 2400×1
2300 F 1 2300×1
sum =2 sum=4700 average=4700/2

Maybe it be complex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文