excel可扩展公式用于多列条件求和

标签 excel array-formulas sumifs

我有任意数量的列,一列对应类(class)提供的每个时期(按时间顺序排列),以及任意数量的行,一列对应每个唯一的参与者。值为“1”表示该月参与,“0”表示不参与。

Fall2019  Spring2019  Fall2018  Spring2018  Fall2017
1  1  0  1  0
0  1  1  1  1
0  1  1  1  1
0  1  1  1  1
0  1  0  1  1
0  1  1  0  0
0  1  1  0  0
0  1  1  0  0
1  0  0  0  0

I would like to take a sum, at the bottom of each column, for how many participants were first time attendees that period, i.e. the sum of '1's where all values in the row to the right of that '1', are '0'. In the given example set, Spring2018 should sum to 1, Fall2018 should sum to 3.

Something like the formula below will work for 'Spring2018' when there is just one previous column to compare:

=SUMPRODUCT((D2:D9)*(E2:E9=0))

但是这个公式不能“自动填充”或跨多列扩展......即这些变体都不起作用:

=SUMPRODUCT((C2:C9)*(D2:$E9=0))
=SUMPRODUCT((C2:C9)*(SUM(D2:$E9)=0))
=SUMPRODUCT((C2:C9)*(SUMIF(D2:$E9,"0")))

虽然它可以工作,但我不想手动创建该公式的扩展版本,例如

=SUMPRODUCT((C2:C9)*(D2:D9+E2:E9=0))
=SUMPRODUCT((B2:B9)*(C2:C9+D2:D9+E2:E9=0))
... and so on

我尝试了 arrayformula、sumproduct 和 sumif 的几种变体,但我真的陷入困境。如有任何帮助,我们将不胜感激。

最佳答案

使用这个数组公式:

=SUM(A2:A10*(MMULT(--(B$2:$E$10=1),TRANSPOSE(COLUMN(B$2:$E$10)^0))=0))

作为数组公式,退出编辑模式时必须使用 Ctrl-Shift-Enter 确认,而不是 Enter。

enter image description here

关于excel可扩展公式用于多列条件求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58029375/

相关文章:

google-sheets - Google 表格 - ARRAYFORMULA 中的 VLOOKUP

google-sheets - 在数组公式中使用 COUNTIFS

excel - 根据唯一值获取最大值

excel - SUMIF 函数多次引用

arrays - Sumif 的数组参数问题

excel - 自动过滤/隐藏不包含数组中单词的单元格行

vba - 错误9 下标超出范围

python - 通过python脚本以mm/cm为单位调整excel中的单元格宽度和高度

ruby - 使用 Ruby 将 CSV 导出到 Excel 的最简单方法是什么?

sql - 如何编写实现 Excel SUMIFS 函数的 SQL 查询