只在引用的设备在列表中时求和,如果不在列表中则返回错误而不是零。

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

Sum If but I only want to sum if the referenced equipment is in the list, return an error not a zero if it isn't in the list

问题

我想要对设备的计数进行求和,如果设备在列表中的话。我有两个列表,一个是部分集合,一个是完整集合。我想要从部分集合中对计数求和,然后放到主集合旁边,但是当设备不在第二个集合中时不要求和为零。

示例:

主列表

A B
设备 求和计数
设备 1 5
设备 2 返回错误,不是零
设备 3 3

第二个列表

C D
设备 计数
设备 1 3
设备 1 2
设备 3 1
设备 3 2

Sumif 不适用,因为它在设备不列出时返回零求和。

英文:

I want to sum the counts for an equipment if the equipment is in the list. I have two lists, one is a partial set, one is the full set. I want to sum the counts from the partial set, next to the main set, but not sum to zero when the equipment is not in the second set.

Example:

Main List

A B
Equipment Sum Counts
Equip 1 5
Equip 2 Return error, not zero
Equip 3 3

Second List

C D
Equipment Counts
Equip 1 3
Equip 1 2
Equip 3 1
Equip 3 2

Sumif doesn't work because it returns a 0 sum when the equipment isn't listed.

答案1

得分: 1

你可以使用 iferrorsumifna 的组合:

=IFERROR(1/(1/SUMIF(C2:C5,A2,D2:D5)), NA())

这样,如果 sumif 的返回值为0,它将返回一个错误,因为它会强制产生 #DIV/0! 错误。

英文:

You can use a combination of iferror, sumif and na:

=IFERROR(1/(1/SUMIF(C2:C5,A2,D2:D5)), NA())

So this will return an error if the return value of sumif is 0 since it forces a #DIV/0! error.

答案2

得分: 1

简单 (复制到下方):

=SUM(FILTER(D$2:D$5,C$2:C$5=A2))

溢出 (单个单元格):

=LET(slData,C2:C5,srData,D2:D5,dlData,A2:A4,
    BYROW(dlData,LAMBDA(dr,SUM(FILTER(srData,slData=dr))))
英文:

Sum Up Filtered Data (Show Errors)

Simple (Copy Down)

=SUM(FILTER(D$2:D$5,C$2:C$5=A2))

Spilled (Single Cell)

=LET(slData,C2:C5,srData,D2:D5,dlData,A2:A4,
    BYROW(dlData,LAMBDA(dr,SUM(FILTER(srData,slData=dr)))))

huangapple
  • 本文由 发表于 2023年3月7日 08:11:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656955.html
匿名

发表评论

匿名网友

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

确定