简体   繁体   English

Excel-基于多个条件的查找值-最近的日期

[英]Excel - lookup value based on multiple criteria - nearest date

I'm having an issue with extracting data from a range - I feel this should be able to be solved via an index/match combination but I haven't been able to make it work so far. 我在从范围中提取数据时遇到问题-我认为应该可以通过索引/匹配组合来解决此问题,但到目前为止我还无法实现。

The range from which I will be extracting the data is structured as follows: 我将提取数据的范围如下:

ID  date    User
1   01/01/2000  BA
1   04/01/2002  JI
1   01/11/2001  PK
2   03/03/2004  DT
2   03/05/2008  BI
2   04/06/2002  KW
3   02/12/2007  NK
3   06/09/2005  LW
3   01/08/2005  DH

I am trying to match a specific ID with col A and date with the the nearest date (up to but not greater than) in col B to extract the User details. 我试图将特定ID与col A匹配,并将日期与col B中最接近的日期(最大但不大于)匹配,以提取用户详细信息。 For example, if I have ID = 1, date = 01/12/2001 - this should return a User value of PK. 例如,如果我的ID = 1,日期= 2001年1月12日-这应该返回用户值PK。

I have tried combining this formula: =MIN(IF(A1:B6>E1,A1:B6)) with index(match * match) to use the ID and date as multiple criteria but I keep getting a #N/A error. 我尝试结合使用以下公式: =MIN(IF(A1:B6>E1,A1:B6))与index(match * match)结合使用ID和日期作为多个条件,但我不断遇到#N / A错误。

This formula will need to be applied to approx. 此公式将需要应用于大约。 1,000 rows and the lookup range is approx. 1,000行,查找范围约为。 65,000 rows. 65,000行。

Any suggestions would be much appreciated. 任何建议将不胜感激。 Cheers, Ant 干杯,蚂蚁

IF you can sort on the first two columns then this normal formula will work: 如果您可以对前两列进行排序,则此常规公式将起作用:

=VLOOKUP(E2,INDEX(B:C,MATCH(D2,A:A,0),0):INDEX(B:C,MATCH(D2,A:A,0)+COUNTIF(A:A,D2)-1,0),2,TRUE)

It will create a smaller range for the Vlookup to search. 它将为Vlookup创建较小的搜索范围。 That smaller data set will include only the dates and users with the correct ID. 该较小的数据集将仅包括日期和具有正确ID的用户。

Again this only works if the data is sorted. 同样,这仅在数据已排序的情况下有效。 If not it will return incorrect values. 如果不是,它将返回不正确的值。

在此处输入图片说明

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

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