+ Reply to Thread
Results 1 to 13 of 13

Lookup and reference for category and date

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Lookup and reference for category and date

    Hy

    I'm having serious difficulties with getting together a formula for a little bit complicated lookup.

    I have 2 tables. In the first table I have categories in the first column (e.g. red, blue, green), in the second column I have dates (DD.MM.YYYY). And in the third column I would like to get the values from the second table.

    In the second table I also have categories in the first column, dates in the second column und values in the third.

    I would now like to get the values from the second table that coincide with the categories. And in addition the dates should also be equal to the date in the first table OR the date from the second table should be as close as possible but BEFORE the date in the first table.


    Example
    Table1
    Red 07.08.2005 ???


    Table 2
    Red 18.04.2005 three
    Blue 11.06.2005 one
    Red 06.08.2005 four


    In this example the value that should be looked up is "four".

    I hope anyone can help me! Thank you!!
    Attached Files Attached Files
    Last edited by Krokes; 07-21-2014 at 02:22 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Lookup and reference for category and date

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Lookup and reference for category and date

    Try,
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This as an array formula, confirmed by Ctrl+Shift+Enter. Input the formula in cell C2, press Ctrl+Shift+Enter and copy down. Is this what you need ?
    If my assistance has helped, there is a reputation icon * on the left hand corner below the post - you can show your appreciation to the user who has helped in resolving your requirement.

    If your requirement has been solved please mark your thread as Solved.
    In the menu bar above the very first post, select Thread Tools, then select "Mark this thread as Solved".

    Kindly use [FORMULA] or [CODE] tags when posting your code.

    Regards,
    Sarang

  4. #4
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    Thank you Saarang84 for the formula. Is it possible that there is a small mistake in it? It doesn't work in my sheet. Ctrl+Shift+Enter doesn't help unfortunatly.

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,944

    Re: Lookup and reference for category and date

    =INDEX('Table 2'!$C$2:$C$5,MATCH(MAX(INDEX(('Table 2'!$A$2:$A$5=$A2)*(9^9+1/(B2+1-'Table 2'!$B$2:$B$5)),0)),INDEX(('Table 2'!$A$2:$A$5=$A2)*(9^9+1/(B2+1-'Table 2'!$B$2:$B$5)),0),0))
    Try this formula and copy towards down
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  6. #6
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    Wow this really seems to solve my problem. Thank you very much. I would love to understand this a little better, could you quickly explain what this formula does? Will it work on a table with a e.g. 60'000 lines?

  7. #7
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,944

    Re: Lookup and reference for category and date

    =INDEX('Table 2'!$C$2:$C$5,MATCH(MAX(INDEX(('Table 2'!$A$2:$A$5=$A2)*(1/(B2+1-'Table 2'!$B$2:$B$5)),0)),INDEX(('Table 2'!$A$2:$A$5=$A2)*(1/(B2+1-'Table 2'!$B$2:$B$5)),0),0))
    This is also will work

  8. #8
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    OK thank you! One thing doesnt work. If I change 'Table 2'!B4 from "17.12.2004" into "18.12.2004", I get #DIV/0! in 'Table 1'!C6. It should actually change the value to "26"

  9. #9
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    And also when I remove all "Blue" lines from Table 2, Table 1 just gets values from category "Red" which is wrong. If there is no corresponding category or date that corresponds, I need an emtpy cell, an error would also be ok. Do you know a solution to that problem?

    Again my problem:
    I need values from the same category (colour) and from the date, that matches the date or from a date that is before the date in Table 1. The category condition alway has to hold. If there is either no category or no date that fits the condition, the cell should be empty or show an error.

  10. #10
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    I have not found the mistake. But When I apply it, I get "28" in Table 1!C4 instead of "25"

    Quote Originally Posted by Saarang84 View Post
    Try,
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This as an array formula, confirmed by Ctrl+Shift+Enter. Input the formula in cell C2, press Ctrl+Shift+Enter and copy down. Is this what you need ?
    I attached another file to make it a bit clearer...
    Attached Files Attached Files
    Last edited by Krokes; 07-21-2014 at 12:08 PM.

  11. #11
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,944

    Re: Lookup and reference for category and date

    =IF(SUM(INDEX((('Table 2'!$A$2:$A$8=$A2)*('Table 2'!$B$2:$B$8<=$B2))*1,0))=0,0,INDEX('Table 2'!$C$2:$C$8,MATCH(SMALL(INDEX(('Table 2'!$A$2:$A$8=$A2)*('Table 2'!$B$2:$B$8)*1,0),SUM(INDEX((('Table 2'!$A$2:$A$8=$A2)*('Table 2'!$B$2:$B$8)<=$B2)*1,0))),INDEX(('Table 2'!$A$2:$A$8=$A2)*('Table 2'!$B$2:$B$8)*1,0),0)))
    try this
    Last edited by samba_ravi; 07-21-2014 at 12:43 PM.

  12. #12
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    Oh my god this work absolutly fantastically!! Thank you so much nflsales!! I will try it on my reallife worksheet and will give feedback again!

  13. #13
    Registered User
    Join Date
    07-21-2014
    Location
    Basel, Switzerland
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup and reference for category and date

    It works very well! Thank you very much!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Lookup top scores by category
    By grkasper in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-10-2014, 10:09 PM
  2. ID lookup for Max Value in a given 'category'
    By thisisntwally in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 12-07-2012, 05:59 PM
  3. LOOKUP value based on date and category!!
    By Si902 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-04-2010, 04:18 PM
  4. Lookup on Date Periods - with another reference
    By grey in forum Excel General
    Replies: 1
    Last Post: 07-14-2009, 06:28 AM
  5. Lookup Problem:Category Name.
    By thomasr79 in forum Excel General
    Replies: 1
    Last Post: 04-24-2007, 06:36 AM

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