+ Reply to Thread
Results 1 to 11 of 11

Index/Match with 2 match columns, non-exact match

  1. #1
    Registered User
    Join Date
    01-24-2019
    Location
    USA
    MS-Off Ver
    Office 365 Ver 16.16.6 for Mac OS El Capitan Ver 10.11.6
    Posts
    7

    Question Index/Match with 2 match columns, non-exact match

    I have a very large sheet of stock data in the format attached.

    I'm trying to come up with formula to determine what date a stock hit a peak or valley, given the stock symbol, starting date, and a target peak or valley.

    For example, what was the first date that stock BBB hit a value of 311.50 or more if purchased on 1/7/19? The correct answer is 1/10/19.

    And, what was the first date that stock BBB hit a value of 299.50 or less if purchased on 1/9/19? The answer is 1/14/19.

    I need a solution that does not include any volatile functions such as VLOOKUP, OFFSET, INDIRECT. I'll be needing to run large Solver optimizations and can't have volatile functions slowing things down.

    We can use additional helper columns beyond Peak and Valley, such as concatenating Symbol and/or Date and/or Peak/Valley. I prefer helper columns because it makes formulas more understandable to other people, not to mention me down the road after I've forgotten how I built a formula.

    The data sheet can remain sorted.

    Many thanks in advance!
    Attached Files Attached Files
    Last edited by c1t; 01-24-2019 at 12:53 PM.

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Index/Match with 2 match columns, non-exact match

    Hello and welcome to the forum.

    VLOOKUP is not a volatile function.

    I can't picture it in my head. I recommend uploading a small representative sample of your data along with the desired results (which you can enter manually) based on that data.

    To upload an Excel workbook, follow these steps:
    1) Click on "Go Advanced"
    2) Click on "Manage Attachments"
    3) Click on "Choose File"
    4) Choose your file and click on "Open"
    5) Click on "Upload"
    6) Click on "Close this window"

  3. #3
    Registered User
    Join Date
    01-24-2019
    Location
    USA
    MS-Off Ver
    Office 365 Ver 16.16.6 for Mac OS El Capitan Ver 10.11.6
    Posts
    7

    Re: Index/Match with 2 match columns, non-exact match

    63falcondude, I uploaded a sample file to the original post, along with 2 examples of desired results in the text of the post.

    You're right, VLOOKUP is not a volatile function. However I seem to remember that INDEX/MATCH runs quite a bit faster than VLOOKUP with sorted data, and speed is a concern given the ultimate intended use.

  4. #4
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Index/Match with 2 match columns, non-exact match

    If you want to do this with a helper column and a simple INDEX MATCH formula, you can do it like this:

    Purchase Date in J2
    Stock in K2
    Price in L2
    Drop down with "or more" and "or less" in M2

    F2 =AND(A2=K$2,B2>=J$2,IF(M$2="or more",C2>=L$2,C2<=L$2))
    Drag the formula down column F. This is your helper column.

    Then you can use this in N2:
    =INDEX(B:B,MATCH(TRUE,F:F,0))

    See attachment.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-24-2019
    Location
    USA
    MS-Off Ver
    Office 365 Ver 16.16.6 for Mac OS El Capitan Ver 10.11.6
    Posts
    7

    Re: Index/Match with 2 match columns, non-exact match

    Fantastic, thank you! That's a better solution than I thought possible. It's simple and easy to understand, and reduces helper columns from 2 to 1 rather than increasing them. Bravo and many thanks!!

  6. #6
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Index/Match with 2 match columns, non-exact match

    Happy to help! I'm glad you like it.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  7. #7
    Registered User
    Join Date
    01-24-2019
    Location
    USA
    MS-Off Ver
    Office 365 Ver 16.16.6 for Mac OS El Capitan Ver 10.11.6
    Posts
    7

    Re: Index/Match with 2 match columns, non-exact match

    Spoke too soon. There's a requirement I forgot to mention when simplifying the problem. It has to solve for more than one case simultaneously.

    I uploaded a new sample showing 5 cases to solve for. In real life application the are hundreds of cases, so adding helper columns for each one would be quite clumsy. I suppose that could be done without a better approach.

    Any thoughts?
    Attached Files Attached Files

  8. #8
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Index/Match with 2 match columns, non-exact match

    Another one

    Date at H2
    Symbol at I2
    Price at J2
    K1 <=
    L1 >=

    K2:L2
    =INDEX($B$2:$B$31,MATCH(1,INDEX(($B$2:$B$31>=$H2)*($A$2:$A$31=$I2)*COUNTIF($J2,K$1&$C$2:$C$31),),))
    Attached Files Attached Files

  9. #9
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Index/Match with 2 match columns, non-exact match

    Okay, I thought that you would be changing the cells in J2:M2. You can clear the helper column.

    Here's one formula that you can use in N2:

    =MIN(IF((B$2:B$31>=J2)*(A$2:A$31=K2)*IF(M2="or more",C$2:C$31>=L2,C$2:C$31<=L2),B$2:B$31)) Ctrl Shift Enter

    Since you have Office 365, MINIFS is available to you so this should work as well (untested since I do not have this function):

    =MINIFS(B$2:B$31,B$2:B$31,">="&J2,A$2:A$31,K2,C$2:C$31,IF(M2="or more",">=","<=")&L2)

  10. #10
    Registered User
    Join Date
    01-24-2019
    Location
    USA
    MS-Off Ver
    Office 365 Ver 16.16.6 for Mac OS El Capitan Ver 10.11.6
    Posts
    7

    Re: Index/Match with 2 match columns, non-exact match

    That last solution with MINIFS works!

    So I made the problem more complicated, and you made the solution even more elegant than your last! (No helper column needed.)

    Very impressive. Thank you so much. I'll mark this Solved.

  11. #11
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Index/Match with 2 match columns, non-exact match

    You're welcome. Glad we could help.

    Thanks for the rep!

+ 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. Index Match Search Not Using Exact Match
    By amartin575 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 01-29-2018, 06:08 PM
  2. Replies: 4
    Last Post: 04-14-2017, 07:47 PM
  3. Using wildcards to get an exact match using vlookup or index and match
    By Martynw2005 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-15-2015, 09:56 PM
  4. INDEX MATCH MATCH/OFFSET MATCH MATCH with named ranges
    By Andrew-Mark in forum Excel General
    Replies: 3
    Last Post: 02-27-2015, 10:56 PM
  5. Replies: 3
    Last Post: 06-17-2013, 12:37 PM
  6. [SOLVED] Index & Match returning incorrect value. Arrays fixed and exact match used.
    By SDes in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-07-2012, 08:29 PM
  7. Replies: 2
    Last Post: 07-02-2006, 05:50 PM

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