简体   繁体   中英

How to match two sets of data by dates which do not synchronise and include missing values in Excel

Please forgive any errors or shortcomings in this question, it's my first on stackoverflow.

I have two sets of data in Excel of differing lengths and frequency, and would like to be able to place a value of 0 for where they don't synchronise, and match the rest.

For example, dataset 1 could be:

Date        Set1
01-01-2010  10
01-03-2010  4
01-04-2010  8
01-05-2010  5
01-06-2010  10
01-09-2010  12
01-10-2010  9
01-11-2010  4

And dataset 2 could be:

Date        Set2
01-03-2010  102
01-06-2010  104
01-10-2010  102

I'm looking for an output table that displays the values alongside each other for dates matching, 0 otherwise, like so:

Date        Set1   Set2
01-01-2010  10      0
01-03-2010  4       102
01-04-2010  8       0
01-05-2010  5       0
01-06-2010  10      104
01-09-2010  12      0
01-10-2010  9       102
01-11-2010  4       0

I can't seem to be able to crack this with my limited knowledge and the lack of synchronisation in the data. Any help would be much appreciated, thanks.

You can do this using a VLOOKUP nested in an IFERROR statement.

The two equations used (and dragged down to last unique date row) are:

H3 = IFERROR(VLOOKUP(G3,A:B,2,0),0)) & I3 = IFERROR(VLOOKUP(G3,D:E,2,0),0))

在此处输入图片说明


This will not work if you have duplicate dates in the same data set with varying values since VLOOKUP will always return the first matched value (reading top down).

Place Set1 in A1:B9 (header in row 1). Add a column of zeros next to it in column C, so A2:A9 is dates, B2:B9 is values and C2:C9 is zeros.

Place Set2 (without the header) in A10:B12; move the Set2 data to column C and put zeros in column B, so A10:A12 is dates, B10:B12 is zeros, C10:C12 is values.

Sort the range A2:C12 by Date (column A).

Easier to show with a screenshot but newbies are not allowed to post images.

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