+ Reply to Thread
Results 1 to 7 of 7

Conditional Lookups

  1. #1
    Registered User
    Join Date
    03-24-2012
    Location
    Sunshine Coast, Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Conditional Lookups

    Hi All,

    Long time lurker first time poster.

    I am having a little trouble with an array formula i constructed.

    "{=INDEX('Data'!$S$7:$S$3050,MATCH(MIN(ABS(IF('Data'!$R$7:$R$3050=E5,'Data'!$Q$7:$Q$3050,999999)-C5)),ABS(IF('Data'!$R$7:$R$3050=E5,'Data'!$Q$7:$Q$3050,999999)-C5),0))}"

    Basically the range S in 'Data' is the data its pulls, range R in 'Data' is the unique identifier code and range Q in 'Data' is the date. Subsequently range E is the unique identifier being looked up and range C is the date being looked up.

    What the array currently does is match the unique identifier and pull the value closest to a date.

    What I am struggling to incorporate is a condition that it cant pull the data before a date. Thus it should only pull the data which is closest to the date it matches that is after the date in range C.


    Thanks for you help guys.
    Last edited by Whirlpool; 03-25-2012 at 06:27 AM.

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Conditional Array Formula

    Firstly, welcome to the speaking/posting world

    Secondly for your question, this can be done, you just need to add in an AND conditoin to the IF portion of your formula, if you post a book it would be alot easier for me to give you the corrected formula. it is difficult to do without the layout and some sample data.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Registered User
    Join Date
    03-24-2012
    Location
    Sunshine Coast, Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Conditional Array Formula

    Hi DGagnon,

    I thought that would be the case im just having trouble slotting it in.

    Please see attached.

    Thanks
    Last edited by Whirlpool; 03-25-2012 at 06:29 AM.

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Conditional Array Formula

    give this formula a shot, its a variation of what you had, but kind of dumbed down a bit, but based on what you were looking for it should work.

    =INDEX(Data!$S:$S,MAX(--(Data!R$7:R$3050=E4)*--(Data!Q$7:Q$3050<=C4)*ROW(Data!Q$7:Q$3050)))

  5. #5
    Registered User
    Join Date
    03-24-2012
    Location
    Sunshine Coast, Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Conditional Array Formula

    Quote Originally Posted by DGagnon View Post
    give this formula a shot, its a variation of what you had, but kind of dumbed down a bit, but based on what you were looking for it should work.

    =INDEX(Data!$S:$S,MAX(--(Data!R$7:R$3050=E4)*--(Data!Q$7:Q$3050<=C4)*ROW(Data!Q$7:Q$3050)))
    Hi Dgagnon thanks for your help,

    Problem is my source database sometimes has anomalies in the data where the data in sheet 1 has a subsequent date earlier than the data sheet. Thus the functionality I was looking to add in was to only pull the later dates data if there was one I have attached the workbook again for further information.

    Basically I want the formula to have the logic of where a match can be found with the code after the date pull that data, however, if no match can be found after that date pull the closest before for that match.


    Thanks for your help once again.

    Cheers
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Conditional Array Formula

    Try this regular formula in J4, then copy down:

    =IFERROR(LOOKUP(2, 1/((Data!$Q$7:$Q$20<=C4)*(Data!$R$7:$R$20=Sheet1!E4)), Data!$S$7:$S$20), INDEX(Data!S:S, MATCH(E4,Data!R:R, 0)))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  7. #7
    Registered User
    Join Date
    03-24-2012
    Location
    Sunshine Coast, Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Conditional Array Formula

    Thanks for all your help guys i ended up with a variation of the formulas you guys helped me with...

    =IFERROR(LOOKUP(2,1/(('Data'!$Q$7:$Q$3055<=C5)*('Data'!$R$7:$R$3055=E5)),'Data'!$S$7:$S$3055),INDEX('Data'!$S$7:$S$3055,MATCH(MIN(ABS(IF('Data'!$R$7:$R$3055=E5,'Data'!$Q$7:$Q$3055,999999)-C5)),ABS(IF('Data'!$R$7:$R$3055=E5,'Data'!$Q$7:$Q$3055,999999)-C5),0)))

    Basically kept my original array formula but changed the front end....

+ 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