哪个公式应该用来按年份分组添加列E的值?

huangapple go评论70阅读模式
英文:

Which formula should I use to add column E values, grouped by year?

问题

例如,对于2023年,该公式应返回E3:E4的总和,并且当我拖动该公式时,对于2022年,它应返回E5:E8的总和。

=SUMIF(B2:B162, YEAR(B2)=2023, E2:E162)

我仅尝试了这个公式用于2023年,但它未返回所期望的答案。

英文:

For example, for year 2023, that formula should return sum of E3:E4, and when i drag down that formula, it should return, for 2022, sum of E5:E8.

哪个公式应该用来按年份分组添加列E的值?

=SUMIF(B2:B162, YEAR(B2)=2023, E2:E162)

I tied this formula for the year 2023 only, but this didnt returned the desired answer.

答案1

得分: 2

你不能在 SumIf 函数内使用 Year 函数。

请改用以下方式使用 Sumproduct

=SUMPRODUCT($E$2:$E$162 * (YEAR($B$2:$B$162) = H2))

它将在付款日期的年份等于 H2 的值时,对所有来自列 E 的单元格求和。

英文:

You can't use the Year-function within SumIf

Use Sumproduct instead like this:

=SUMPRODUCT($E$2:$E$162 * (YEAR($B$2:$B$162) = H2))

It will sum all cells from E whenever Year of accordin`g payment date equals the value from H2.

答案2

得分: 0

不要使用SUMIF函数,我建议使用SUMIFS函数,它可以接受多个条件。

注意SUMIFS将要求求和的范围移到成为第一个参数,并将其设为必填,而不像SUMIF,它是最后的参数,并且是可选的。

=SUMIFS($E$2:$E$162, $B$2:$B$162, ">=" & DATE($H2, 1, 1), $B$2:$B$162, "<" & DATE($H2+1, 1, 1))

"将列E中的值求和,其中列B在今年的1月1日或之后,并且列B在明年的1月1日之前"

英文:

Rather than use the SUMIF function, I would recommend using the SUMIFS function, which accepts multiple criteria.

N.B. SUMIFS moves the range to be summed to become the first argument, and makes it Mandatory — unlike SUMIF where it was the last argument, and was Optional.

=SUMIFS($E$2:$E$162, $B$2:$B$162, &quot;&gt;=&quot; &amp; DATE($H2, 1, 1), $B$2:$B$162, &quot;&lt;&quot; &amp; DATE($H2+1, 1, 1))

"Sum the values in Column E, where Column B is on-or-after 1st January of this year, and Column B is before 1st January of next year"

huangapple
  • 本文由 发表于 2023年8月10日 16:59:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定