简体   繁体   English

如何在libreoffice calc中计算平均年薪

[英]How to calculate average annual salary in libreoffice calc

I have salary data.table from 10 years period.我有 10 年的工资 data.table。 Every column has properly set data type (date for "B", number for "C" and "E".每列都有正确设置的数据类型(“B”的日期,“C”和“E”的数字。

样本数据表

I'm trying to write a formula to calculate average salary for every year.我正在尝试编写一个公式来计算每年的平均工资。 In column "E" I've manually entered all possible years and in column "F" should be an yearly average, according to year from "E".在“E”列中,我手动输入了所有可能的年份,在“F”列中,根据“E”中的年份,应该是年平均值。

So, my best try is this formula: =AVERAGEIF(YEAR(B2:B133);"="&E2;C2:C133)所以,我最好的尝试是这个公式: =AVERAGEIF(YEAR(B2:B133);"="&E2;C2:C133)

Trying so calculate an average from column C, where year in date from column B equals a year in column E尝试计算 C 列的平均值,其中 B 列日期中的年份等于 E 列中的年份

平均公式

But all I get is an error Err:504.但我得到的只是一个错误 Err:504。 Figured out, that problem is in YEAR(interval) part, but can't get what exactly...想通了,这个问题是在YEAR(interval)部分,但无法得到究竟是什么......

Can someone point that out?有人可以指出吗?

Thank you!谢谢!

Unfortunately AVERAGEIF() expects a range reference instead of a calculated array.不幸的是AVERAGEIF()需要一个范围引用而不是一个计算数组。 Therefor it will error out.因此它会出错。 That's the theory at least for Excel, and I expect this to be the same for LibreCalc.至少 Excel 是这样的理论,我希望 LibreCalc 也是如此。

One way around it is using the AVERAGEIFS() function and check against first and last days of the year, for example:一种解决方法是使用AVERAGEIFS() function 并检查一年中的第一天和最后一天,例如:

=AVERAGEIFS(C$2:C$133;B$2:B$133;">="&DATE(E2;1;1);B$2:B$133;"<="&DATE(E2;12;31))

Drag the formula down.向下拖动公式。

There are actually many possibilities to solve this.解决这个问题其实有很多可能性。

  • @JvdV answer ; @JvdV回答
  • using an array formula with @JvdV solution;使用带有@JvdV 解决方案的数组公式;
  • using an array formula with a combination of AVERAGE() and IF() ;使用结合了AVERAGE()IF()的数组公式;
  • using the SUMPRODUCT() function;使用SUMPRODUCT() function;
  • and surely many other solutions that I don't know about!当然还有许多我不知道的其他解决方案!

Please beware: I use , instead of ;请注意:我使用,而不是; as formula separator, according to my locale;作为公式分隔符,根据我的语言环境; adapt to your needs.适应您的需求。

A side note on "array formulas"关于“数组公式”的附注

This kind of formulas are applied by mandatory pressing the Ctrl + Shift + Enter key combination to insert them, not only Enter or Tab or mouse-clicking elsewhere on the sheet.此类公式的应用是通过强制按下Ctrl + Shift + Enter组合键来插入它们,而不仅仅是EnterTab或在工作表上的其他地方单击鼠标。
The resulting formula is shown between brackets {} , which are not inserted by the user but are automatically shown by the software to inform that this is actually an array formula.生成的公式显示在括号{}之间,这不是用户插入的,而是软件自动显示的,以告知这实际上是一个数组公式。
More on array formulas ie on the LibreOffice help system .有关数组公式的更多信息,即在 LibreOffice 帮助系统上

Usually you cannot drag and drop array formulas, you have to copy-paste them instead.通常你不能拖放数组公式,你必须复制粘贴它们。

Array formula with @JvdV solution带有@JvdV 解决方案的数组公式

The solution of JvdV could be slighly modified like this, and then inserted as an array formula: JvdV 的解决方案可以像这样稍微修改,然后作为数组公式插入:

=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2) =AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)

When you insert this formula with the Ctrl + Shift + Enter key combination, the software puts the formula into brackets, so that you see it like this: {=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)}当您使用 Ctrl + Shift + Enter 组合键插入此公式时,软件会将公式放入括号中,因此您会看到这样的公式: {=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)}

You cannot simply drag the formula down, but you can copy-paste it.您不能简单地向下拖动公式,但可以复制粘贴它。

Array formula with a combination of AVERAGE() and IF() :结合AVERAGE()IF()的数组公式:

For your example, put this formula in cell F2 (for the year 2010):对于您的示例,将此公式放在单元格F2中(2010 年):

=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133)) =平均(如果(年($B$2:$B$133)=E2,$C$2:$C$133))

When you insert this formula with the Ctrl + Shift + Enter key combination, the software puts the formula into brackets, so that you see it like this {=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133))}当您使用Ctrl + Shift + Enter组合键插入此公式时,软件会将公式放入括号中,因此您会看到这样的{=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133))}

You cannot simply drag the formula down, but you can copy-paste it.您不能简单地向下拖动公式,但可以复制粘贴它。

SUMPRODUCT() formula: SUMPRODUCT() 公式:

My loved one...我爱的人...
Plenty of resources on the web to explain this formula. web 上有很多资源可以解释这个公式。
In your situation, this would give:在您的情况下,这将给出:

=SUMPRODUCT($C$2:$C$133,--(YEAR($B$2:$B$133)=E2))/SUMPRODUCT(--(YEAR($B$2:$B$133)=E2)) =SUMPRODUCT($C$2:$C$133,--(年($B$2:$B$133)=E2))/SUMPRODUCT(--(年($B$2:$B$133)=E2))

This one you can drag down to your needs.这个你可以拖到你的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM