+ Reply to Thread
Results 1 to 14 of 14

Matching data between tables with a column being time values

  1. #1
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118

    Matching data between tables with a column being time values

    Hi all and congratulations for all the help you are providing

    here is my problem

    I have two tables

    one which has two columns and the another with three columns

    It is basically like this
    Table 1 __________ _________________________ Table 2
    A_______________ B ____________ F _______________G___________ H
    Number_________Time__________Number ________ Time _________ Value
    1 __________ 14:02:00 __________ 2 __________ 14:03:30 _________ 7
    2 __________ 14:05:00 __________ 5 __________ 14:04:00 _________ 10
    3 __________ 14:08:00 __________ 1 __________ 14:07:00 _________ 15
    4 __________ 14:10:30 __________ 4 __________ 14:11:30 _________ 4
    5 __________ 14:12:00 __________ 3 __________ 14:13:00 _________ 2


    As you noticed the time columns in the two tables are not exactly matching.

    What I want to do is the following

    match the number columns from table 1 with the number columns from table 2 AND match the Time column from table 1 with the Time column in Table 2 and then get whatever is in the Value column of table 2 as a result.

    My main problem is that the times are not absolute matches. Therefore I have to implement a check that matches the Number columns and then matches the Time columns based on their proximacy and afterwards returns the value on the Value column (table 2).

    I tried the sumproduct function but I can't seem to be able to implement the > or < signs so that I could possible have something like this:

    =SUMPRODUCT(--(A1:A5=F1:F5),--(H1:H5<C1:C5),G1:G5)

    or

    =SUMPRODUCT(--(A1:A5=F1:F5),--(H1:H5<C1+TIME(0,5,0)),G1:G5

    I tried the second formula to add some slack time in the table 2 Time column in case it would help the calculations (sometimes the Time value in Table 1 might be equal or slightly higher than the Time value in Table 2, so I want to be able to add an extra -standard- time in minutes to the Time column in Table 2).

    So basically I want something that calculates this

    IF the Number column in Table 1 is equal to the Number column in Table 2 _AND_ the Time column in Table 1 is between a 15 minute proximity with the Time column in Table 2, give me the value in the Value column in Table 2.

    So , any ideas ? I would be grateful!
    Last edited by kostas; 03-21-2007 at 08:21 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Should the answer for this example be 4?

    If so, =SUMPRODUCT(--(A2:A6=F2:F6),--((B2:B6-G2:G6)*24<=0.25),H2:H6)
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    Hi,
    thank you for answering but I feel I have not made clear what I want

    I need to create a new column in table 1 (e.g column C) where I can place the corresponding values.

    So I want to match Number 4 from T1 with Number 4 from T2 AND the Time match between T1 and T2 to extract the corresponding value from T2 and put it in T1 C column.

    Therefore as an example I would like to see in C1 the value 15.

    Take into account that I might have the same Number values repeating in Table 2 at different times, but I want the VALUE column's value that corresponds to the one with the greatest proximity in regards to the Time column's values.

    Hope this make it a bit more clear.

    Another example would be:

    Table 1 __________ _________________________ Table 2
    A_______________ B ____________ F _______________G___________ H
    Number_________Time__________Number ________ Time _________ Value
    1 __________ 14:02:00 __________ 2 __________ 14:03:30 _________ 7
    2 __________ 14:05:00 __________ 5 __________ 14:04:00 _________ 10
    3 __________ 14:08:00 __________ 1 __________ 14:07:00 _________ 15
    4 __________ 14:10:30 __________ 4 __________ 14:11:30 _________ 4
    5 __________ 14:12:00 __________ 3 __________ 14:13:00 _________ 2
    6 __________ 14:12:00 __________ 1 __________ 14:33:00 _________ 22

    In this table (I just added an extra line to the previous one to illustrate what I want) I need to still get the Value 15 in a potential Table 1 C column cell C1.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    so then something like this in C2 copied down?

    =SUMPRODUCT(--($F$2:$F$6=A2),--(($G$2:$G$6-B2)*24<=0.25),$H$2:$H$6)

  5. #5
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    This seems to give a result, although wrong.

    Please see the attached file to get an idea of what kind of data I have and what I am looking to achieve.

    Please note that Table 1 and Table 2 have different number of rows.

    Thank you VERY much for trying to help.
    Attached Files Attached Files

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Try this formula, copied down:

    =IF(ISNUMBER(MATCH(A3,$E$3:$E$569,0)),MIN(IF($E$3:$E$569=$A3,IF(ABS($F$3:$F$569-($B3-INT($B3)))*24<=0.25,$G$3:$G$569))),"N/A")

    Formula must be confirmed with CTRL+SHIFT+ENTER not just ENTER

    See attached file

    Hope this helps!
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    From a first quick verification of the results it seems to be the ONE!!!!

    I will thoroughly check it tommorow and cross-examine the results it produces against a lot of data to make sure that the results are accurate. I suppose it might need a small fine-tuning on the proximity factor.

    If I understand right the 0.25 is the variation from the desired Time match right? In case there is any discrepancy between the results produced and the results that are wanted I might have to play around with that factor.

    I really appreciate your help. You have been extremely kind and helpful to spend your time and gray matter on something that is bugging me!

    I am proud to be a member of a board with such helpful people.

    I will report back on the results tommorow!

    Again, thank you very much.

    Kostas

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    You are most welcome!

    The 0.25 represents 15 minutes (i.e. 1/4 hour). You can go smaller or larger if depending on the precision you need.

    I look forward to your test results.

    Have a good day.

  9. #9
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    Well,

    I checked it today against many manually-made spreadsheets and it works like a charm!!

    The only thing I need to do is to place a check on the column to set a flag when it returns "0" as a result so I can manually fix the specific cell and that I can do it easily. Of course this doesn't have to do with the formula itself but with the data which in some rare occasions they might be quirky enough to have a larger spread than the 15 minutes set in the formula. This can easily be mended by increasing the spread, right now I've put it to 20 mins and it works perfect!

    I even spotted some mistakes I had done with the manual method!

    A good thing that I noticed about the formula is that exactly because it calculates the spread of the difference you can even have higher values in the first table than those in the second and it will still give back a correct result! (sometimes I might have a value of 1 minute or 30 seconds higher than the one in the second table, although this happens rarely, still the formula caters for it!)

    Thank you very much for all the help. The formula works perfect.

    Kind regards,

    Kostas

    p.s I am wondering about something. With the formula we are able to pull the cell values from the table two and bring them to table 1. Would it be possible along with the value in the T2 VALUE column to grab the value in the T2 TIME column (the one we compare the TIME value in T1 to) as well and place it in a fourth column in T1?

    So the result table in T1 would be something like (e.g)

    A_____B_______C__________D
    12__08:00:00__5________08:04:00

    or would it become way too complicated? If it is too complicated never mind, cause I can just simply alter the formula and instead of grabbing the VALUE column values I can ask it to grab the TIME columb values from T2 and just copy the formula to a new column.

    Thanx!
    Last edited by kostas; 03-22-2007 at 06:32 AM.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by kostas
    Well,

    I checked it today against many manually-made spreadsheets and it works like a charm!!

    The only thing I need to do is to place a check on the column to set a flag when it returns "0" as a result so I can manually fix the specific cell and that I can do it easily. Of course this doesn't have to do with the formula itself but with the data which in some rare occasions they might be quirky enough to have a larger spread than the 15 minutes set in the formula. This can easily be mended by increasing the spread, right now I've put it to 20 mins and it works perfect!

    I even spotted some mistakes I had done with the manual method!

    A good thing that I noticed about the formula is that exactly because it calculates the spread of the difference you can even have higher values in the first table than those in the second and it will still give back a correct result! (sometimes I might have a value of 1 minute or 30 seconds higher than the one in the second table, although this happens rarely, still the formula caters for it!)

    Thank you very much for all the help. The formula works perfect.

    Kind regards,

    Kostas

    p.s I am wondering about something. With the formula we are able to pull the cell values from the table two and bring them to table 1. Would it be possible along with the value in the T2 VALUE column to grab the value in the T2 TIME column (the one we compare the TIME value in T1 to) as well and place it in a fourth column in T1?

    So the result table in T1 would be something like (e.g)

    A_____B_______C__________D
    12__08:00:00__5________08:04:00

    or would it become way too complicated? If it is too complicated never mind, cause I can just simply alter the formula and instead of grabbing the VALUE column values I can ask it to grab the TIME columb values from T2 and just copy the formula to a new column.

    Thanx!

    Well, thank you so much for this positive feedback. It makes me feel good to have helped you in this project. It is responses like yours that make it worthwhile to continue to frequent these forums and help out as much as possible. Again thank you!

    For your last query, try this formula in D3:

    =INDEX($F$3:$F$569,MATCH(1,($E$3:$E$569=A3)*($G$3:$G$569=C3),0))

    Again, once you enter the formula, confirm it with CTRL+SHIFT+ENTER not just ENTER....you'll see curly {} brackets appear around the formula....

    then copy the formula down the column....

    Note: Any NA's or 0's in column C will correspond with an #N/A error to advise you of no matches found.

    Hope this helps.

  11. #11
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    Yeap!

    It works perfect as well.

    However I was more interested if it was possible to do both things with one formula, kind of merging the two formulas in one.

    What this last formula achieves can also be done with a little tweaking of the previous one you gave me.

    =IF(ISNUMBER(MATCH(A3,$E$3:$E$569,0)),MIN(IF($E$3: $E$569=$A3,IF(ABS($F$3:$F$569-($B3-INT($B3)))*24<=0.25,$G$3:$G$569))),"N/A")

    just by chaning the ending $G$3:$G$569 to the F column, thus instead of grabbing the VALUE column values it grabs the TIME column values.

    Thank you for such quick replies. There is no real need to bother with merging the two formulas (unless you can come up with a quick fix cause I don't really want to get you in a lot of trouble working for something that is not as critical).

    Great to be in this forum!

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Yes, I guess that formula, tweaked the way you said would work too...but it returns 12:00 were your times were not found within the constraints....(i.e. where value in C is 0)...so beware....

    To "merge" the 2 results into one column you can concatenate and minipulate the time result to return correctly:

    Try this in C3, confirmed with CTRL+SHIFT+ENTER:

    =IF(ISNUMBER(MATCH(A3,$E$3:$E$569,0)),MIN(IF($E$3:$E$569=$A3,IF(ABS($F$3:$F$569-($B3-INT($B3)))*24<=0.25,$G$3:$G$569)))&" - "&TEXT(MIN(IF($E$3:$E$569=$A3,IF(ABS($F$3:$F$569-($B3-INT($B3)))*24<=0.25,$F$3:$F$569))),"h:mm:ss AM/PM"),"N/A")

  13. #13
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    Well,

    if the error is only when 0 appear that should be no problem because I delete all lines with 0 in C column manually as I check the results. There are always 2-3 of them.

    About the formula, I do not want to merge the results in one column. I want to have one formula that grabs the VALUE column values and puts them into the C column and at the same time grabs the TIME column values and puts them into a D column. I just thought it might be possible without entering a formula anew into column D as you suggested above.

    Thanks for the tip though I will learn a lot from it.

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    No, you can't do that. There has to be a formula in each cell you want to display a result in.....

    Unless you use VBA...but that will still need programming to do what you want.

    Best bet is use the 2 formulas....

    Try the alternative formula I gave you for column D....it might be faster. Not sure though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1