简体   繁体   中英

Excel how to find the closest date to another date, matched for the same ID number in two sets of data?

I have two excel sheets, each sheet has a list of ID numbers and multiple dates associated with these ID numbers. I want to find the closest date on the second sheet of data to the date on first sheet, matched to the same ID. For example, for ID 1234 01/24/2012 on sheet one, I want to be able to know the closest date for ID 1234 to that date on sheet 2.

Try this array formula:

{=INDEX($G$1:$G$10,MATCH(MIN(ABS(B1-$G$1:$G$10*(A1=$F$1:$F$10))),ABS(B1-$G$1:$G$10*(A1=$F$1:$F$10)),0))}

Array formula after editing is confirmed by pressing ctrl + shift + enter

在此处输入图片说明

Using the Dynamic Array formula available in Office 365:

=FILTER(FILTER(G1:G11,F1:F11=A1),@SORT(ABS(B1-FILTER(G1:G11,F1:F11=A1)))=ABS(B1-FILTER(G1:G11,F1:F11=A1)))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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