简体   繁体   English

根据日期条件返回匹配项的数组公式

[英]Array formula to return match based on date criteria

The following codes works great for me when my data is stored in row 2 and below. 当我的数据存储在第2行及以下行时,以下代码对我来说非常有用。 But if my array range is from row 6 and below, how do I adapt the formula? 但是,如果我的数组范围是从第6行开始,则该如何调整公式? Thanks in advance 提前致谢

=IF(ISERROR(INDEX(Array_Range,SMALL(IF(Health_Check_Date<DATE(YEAR(TODAY())-2,MONTH(TODAY()),DAY(TODAY())),ROW(Health_Check_Date)),ROW($1:$1)),1)),"",INDEX(Array_Range,SMALL(IF(Health_Check_Date<=DATE(YEAR(TODAY())-2,MONTH(TODAY()),DAY(TODAY())),ROW(Health_Check_Date)),ROW($1:$1)),1))

Named Ranges: Array_Range = $A$6:$B$9 Health_Check_Date = B$6$:$B$9 命名范围:Array_Range = $ A $ 6:$ B $ 9 Health_Check_Date = B $ 6 $:$ B $ 9

Sample Data (From row 5 onwards) 样本数据(从第5行开始)

A       B
Test1   18/05/2015
Test2   15/05/2015
Test3   19/05/1991
Test4   18/05/2013

When your data started in row 2, you were actually offsetting by one row down. 当数据从第2行开始时,实际上实际上是向下偏移了一行。 This problem was magnified when you shifted the data down to start in row 6. This is due to the difference of returning the worksheet row and the row position within a named range. 当您向下移动数据以从第6行开始时,此问题被放大了。这是由于返回工作表行和该行在指定范围位置的差异。 If Health_Check_Date refers to B6:B9 then wrapping the ROW function around a match on the first row is going to return a 6 , not a 1 . 如果Health_Check_Date引用B6:B9,则将ROW函数包装在第一行的匹配项周围将返回6 ,而不是1 You need to adjust hte return by the starting row of Health_Check_Date . 您需要在Health_Check_Date的开始行调整返回

Your formula was designed to return the first, second, third, etc matches into successive row but you had locked this out with the absolute addresses in ROW($1:$1) . 您的公式旨在将第一,第二,第三等匹配项返回到连续的行中,但是您已使用ROW($1:$1)的绝对地址将其锁定。 I've removed that restriction. 我已取消该限制。

The EDATE function is a more efficient way to knock a couple years off today. EDATE功能是一种有效的方法,可以将今天缩短两年。

The IFERROR function reduces the doubling up of the formula that an IF(ISERROR(... requires by evaluating the formula and returning the default if it is in error ot the formula's result if it is not. IFERROR函数通过评估公式并返回默认值(如果错误)或返回默认值(如果不是),来减少IF(ISERROR(...要求的公式加倍。

小索引Array_Range

The array formula in D1 is, D1中的数组公式

=IFERROR(INDEX(Array_Range, SMALL(IF(Health_Check_Date<EDATE(TODAY(), -24), ROW(Health_Check_Date)-ROW(INDEX(Health_Check_Date, 1, 1))+1), ROW(1:1)), 1), "")

If blank cells in Health_Check_Date need to be discarded, stack an extra IF into the works that ignores zero length. 如果需要丢弃Health_Check_Date中的空白单元格, 则将一个多余的IF堆叠到忽略零长度的工作中。

=IFERROR(INDEX(Array_Range, SMALL(IF(LEN(Health_Check_Date), IF(Health_Check_Date<EDATE(TODAY(), -24), ROW(Health_Check_Date)-ROW(INDEX(Health_Check_Date, 1, 1))+1)), ROW(1:1)), 1), "")

Array formulas need to be finalized with Ctrl + Shift + Enter↵ (but you knew that!). 数组公式需要使用Ctrl + Shift + Enter 完成 (但您知道!)。 Fill down for subsequent returns. 填写后续退货。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM