Excel 2013 - 如何让查找返回指定日期之后的第一个日期?

Excel 2013 - 如何让查找返回指定日期之后的第一个日期?

因此,我希望创建一个函数,在一列中搜索唯一 ID 代码,并从另一列返回相应的时间戳。但是,每个唯一 ID 代码都附有多个时间戳。我只想返回紧跟在指定时间之后的时间戳。

例如,对于唯一 ID“9f45Q3”,其附带有 4 个时间戳:

  • 11:00
  • 11:15
  • 11:40
  • 11:55

我需要找到一种方法来告诉 Excel 返回紧跟在 11:30 之后的“9f45Q3”的时间戳。(只是为了解释而任意指定一个时间)在这种情况下,我希望 Excel 返回 11:40,因为它紧跟在我指定的时间之后。

任何帮助都将不胜感激。谢谢!

答案1

使用 INDEX 和 AGGREGATE

使用聚合来确定符合您的条件的行号或第二个或第三个。 在您的情况下是第二个。 AGGREGATE 执行类似数组的操作,因此您需要避免使用完整的列引用。

=AGGREGATE(14,6, row(range of interest)/(true condition check(range of interest)*true condition check n (range of interest)),2)

14 tells AGGREGATE to sort an array of results from smallest to largest.

 6 tells AGGREGATE to ignore any errors and exclude them from the array of results)

ROW(range of interest) will return the row number corresponding to the current calculation

Condition check will be some formula you come up with that returns a TRUE or FALSE result.  If it is false it will result in a divide by 0 calculation which the 6 will tell aggregate to ignore.  You can apply multiple conditions and separate them by a * which will act as an AND function.
 2 tells AGGREGATE to return the 2nd result in the sorted array.  So in this case it should be the second row number that matches your results.

接下来要做的是将 AGGREGATE 函数放在 INDEX 中,以便它返回您想要的信息。由于 INDEX 不执行类似数组的计算,因此可以安全地使用完整的列引用。假设您的时间戳在 B 列中。您的索引公式将如下所示:

=INDEX(B:B,AGGREGATE())

所以最后假设您的 ID 在 A2:A8 范围内,而您的时间戳在 B2:B8 范围内,并且您要查找的 ID 代码在 C1 中,那么您的公式可能如下所示:

=INDEX(B:B,AGGREGATE(14,6,ROW(A2:A8)/(A2:A8=C1),2)

现在如果您想添加一些错误检查,您可以包含 IFERROR 函数并使其看起来像:

=IFERROR(INDEX(B:B,AGGREGATE(14,6,ROW(A2:A8)/(A2:A8=C1),2),"Could NOT find the darned thing")

相关内容