我有任意数量的列,一列对应类(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。
关于excel可扩展公式用于多列条件求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58029375/