数组公式查找最后一个匹配条件

Array formula to find the last matching condition

我想用数组公式做一些有点怪异的事情。我快到了,但无法将最后一块放到位。

假设我有这样的数据行...

 Property 1      Property 2      Property 3
 Orange          Square          Hot
 Blue            Circle          Cold
 Purple          Star            Slimy

我有一个 table 标准,包括一个要检查的列和一个要匹配的值:

 Property Index      Value
 2                   Circle
 1                   Purple
 3                   Slimy

对于每一行数据,我试图确定该行数据满足的最后一个标准。

即。对于上面的三行数据,我希望得到以下输出:

0 <- a hot orange square isn't slimy or purple or a circle
1 <- a cold blue circle matches (only) the circle criterion
3 <- a slimy purple star is both purple and slimy, 
     and we count the last match

到目前为止,我已经在单个单元格中尝试了这个数组公式:

 {=MAX(
     IF(
        INDEX(Data[@[Property 1]:[Property 3]], Criteria[Property Index])
        = Criteria[Value],
            ROW(Criteria[Value]),
            0
     )
  )}

问题在于,当我逐步计算公式时,Criteria[Property Index] 仅计算第一个条目的值 2,而不是整个列 {2, 1, 3} , 所以我只是反复测试第一个标准。

我希望使用这个索引范围来查找每行的排列列表 {Square, Orange, Hot}{Circle, Blue, Cold}{Star, Purple, Slimy},以与值进行比较范围。

当公式跨越多个单元格时,我已经能够让 INDEX 为索引使用一系列值,并且 return 每个索引结果的数组,但我试图避免绑定我的sheet 到 Criteria table 的固定长度。我希望能够向其中添加更多行并让公式仍然有效。

在这种情况下,有什么方法可以让 Excel 将索引参数视为一个范围,以获得我想要的数组输出吗?或者是否有另一种方法可以执行此计算,该计算仍将随着用户 add/remove 行条件的缩放?

这是可行的,但是使用命名范围封装数据 table

的严格 属性 列是个好主意
=MAX(IF(
        INDEX(
              INDEX(PropertyData, 1 + ROW()-ROW($I), 0),
              1,
              N(IF({1}, Criteria[Property Index]))
        ) = Criteria[Value],
        ROW(Criteria[Value])-ROW(Criteria[#Headers]),
        0
))

属性数据是 属性 1 列中的第一个单元格,通过 命名范围 .

属性数据定义为:

=INDEX(Data, 1, COLUMN(Data[Property 1])-COLUMN(Data) + 1):INDEX(Data, ROWS(Data), COLUMNS(Data))

一个硬编码值是第一个公式所在的 $I$15 单元格。我将 table 和公式不同步,以显示它处理得很好。