如何根据多个值检查一个值是部分值、完整值还是 none

How to check if a value is partial, full, or none based on multiple values

我有一个名称列和一个名为的列违反了规则。

我知道如何在 python 中以编程方式执行此操作,但是如何在 excel 中检查它们的实际违规状态?

name broke rule
bob no
bob no
jane no
sam yes
jane yes
jake no
bob yes
paul no

我想要的结果

name broke rule rule breaking status
bob no partial
bob no partial
jane yes rule breaker
sam yes rule breaker
jane yes rule breaker
jake no rule follower
bob yes partial
paul no rule follower
jake no rule follower

我有这个公式,但它只告诉我它们是否 rule follower 或者是否至少违反了一次规则。

=IF(COUNTIFS(A:A,A2,B:B,"No"),"Broken rule at least once","Rule follower")

您的定义意味着您可以为每个人计算 Times rule followed / Total times attempted。如果那个数字是 0,那么这个人就是 rule breaker。如果是 1,则此人是规则追随者。否则,它们是 partial.

因此,根据您的布局(并假设数据有 header 行),我们可以将 C2 写为:

=COUNTIFS($A:$A, $A2, $B:B, "yes") / COUNTIF($A:$A, $A2)

$A:$A是名称范围,$B$:$B是布尔值范围。然后,您可以将 D2 写为:

=IF(C2=1, "rule breaker", IF(C2=0, "rule follower", "partial"))

根据@crcvd公式,在C2中输入此公式:

= LOOKUP( INT( 10 * COUNTIFS($A:$A, $A2, $B:$B, "yes") / COUNTIF($A:$A, $A2) ),
 {0,"rule follower";1,"partial";10,"rule breaker"} )

其实这个也行:

= LOOKUP( COUNTIFS($A:$A, $A2, $B:$B, "yes") / COUNTIF($A:$A, $A2),
 {0,"rule follower";0.01,"partial";1,"rule breaker"} )