+ Reply to Thread
Results 1 to 13 of 13

Find value matching multiple text criteria and max date

  1. #1
    Registered User
    Join Date
    06-07-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    5

    Find value matching multiple text criteria and max date

    Hello,

    I have the following dataset:

    [Date] [Category] [Currency] [ExchangeRate] [.....], etc.
    1-3-09 A USD 0,8
    1-6-09 A EUR 1
    1-7-09 A USD 0,7
    1-8-09 B USD 0,9
    1-9-09 B USD <formula>

    I'd like to have the value of <formula> looked up in older records. Currency and category should match and it should pick the exchange rate with the maximum date.

    Which formula and what syntax should I use to have this done?

    Thanks in advance for any help offered. I use Excel 2007.

    Kind regards,


    Rolf

  2. #2
    Forum Contributor mubashir aziz's Avatar
    Join Date
    03-18-2009
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2013
    Posts
    533

    Re: Find value matching multiple text criteria and max date

    You can write below formula for Category A & Currency USD

    =OFFSET(INDIRECT(ADDRESS(SUM((MAX((B2:B6="A")*(C2:C6="USD")*(A2:A6))=(B2:B6="A")*(C2:C6="USD")*(A2:A6))*ROW(A2:A6)),1)),0,3)

    In attached sheet i've written formula for referenced cells as well.
    Attached Files Attached Files
    If this post helps, Please don't 4get to click the star icon located at the bottom left of my Post.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find value matching multiple text criteria and max date

    If the dates are sorted in Ascending order (key) you could use LOOKUP

    If we assume your example data were in A1:D6 with row 1 being headers then the <formula> in D6 would be:

    =LOOKUP(2,1/(($B$1:$B5=$B6)*($C$1:$C5=$C6)),$D$1:$D5)

  4. #4
    Forum Contributor mubashir aziz's Avatar
    Join Date
    03-18-2009
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2013
    Posts
    533

    Re: Find value matching multiple text criteria and max date

    @ DK very thought full approach but optional with dates .....

    Forum missed you a lot and many post went on other pages without replying as you were not there ... This post was in my mind and i had the file with me but had idea that you must be get some short solution of the problem ....

  5. #5
    Registered User
    Join Date
    06-07-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find value matching multiple text criteria and max date

    Hi mubashir aziz & DonkeyOte,

    Thanks both for your reply. Unfortunately, I can't sort them AZ so I tried the solution mubashir aziz supplied.

    It's working, but I need an additional feature; I need the formula to be part of the datatable (some exchange rates will be entered, whereas others will be referenced). So I need to use relative references. I tried to do that using the INDIRECT() combined with the ROW() function to create a range reference to $C2:$C6 but it's not working.

    It seems that the ROW function doesn't work in combination with your formula. Because when I use the same function without ROW it's working (see yellow row). Also, when I use the ROW function in combination with a simple SUM then it's also working (see orange row).

    Do you have any clue on this? See attached file for details..

    Kind regards,


    Rolf
    Attached Files Attached Files

  6. #6
    Forum Contributor mubashir aziz's Avatar
    Join Date
    03-18-2009
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2013
    Posts
    533

    Re: Find value matching multiple text criteria and max date

    You can put formula in separate columns except A to C and extend your range upto 1000 ................

    =OFFSET(INDIRECT(ADDRESS(SUM((MAX((INDIRECT("$C$2:$C$"&ROW($C7))=$C8)*(INDIREC
    T("$A$2:$A$"&ROW($A7))))=(INDIRECT("$C$2:$C$"&ROW($C7))=$C8)*(INDIRECT("$A$2:$A$"&ROW($A7))))*ROW(INDIRECT("$A$2:$A$"&ROW($A7)))),1)),0,3)
    I also worked in your formula and instead of using row($c7) you can use Row()-1 INDIRECT("$C$2:$C$"&ROW()-1) but Me too astonished its not working .... Instead of this if you put INDIRECT("$C$2:$C$"&6-1) then its working .....

    i think DK or some expert can put some light on it that why INDIRECT("$C$2:$C$"&ROW()-1) is not working .....
    Last edited by mubashir aziz; 06-11-2009 at 12:41 AM.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find value matching multiple text criteria and max date

    I confess I don't really understand the question exactly... it's also not clear to me if the date should be restricted based upon the date in Column A of the current row, for ex. in row 8 given the date is 3rd May should the value applied be the last assigned to the same currency before or on the date of A8 ?

    ie you could use shorter (non volatile) array of:

    D8:
    =INDEX($D$2:$D7,MATCH(MAX(IF($C$2:$C7=$C8,$A$2:$A7))&$C8,$A$2:$A7&$C$2:$C7,0))
    committed with CTRL + SHIFT + ENTER

    this would return 25 as it will return the value of D5 (the rate assigned to the MAX date where USD is currency), however, the date in A5 exceeds that of A8... is that correct ?

    I would suggest providing a slightly larger sample if possible clearly denoting desired results entered manually - working off small datasets makes it difficult to determine logic etc...

  8. #8
    Forum Contributor mubashir aziz's Avatar
    Join Date
    03-18-2009
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2013
    Posts
    533

    Re: Find value matching multiple text criteria and max date

    In my attached Sheet you can see formulas. Although we can adopt other ways as well but i'm very much confused with the behavior of Row() function in below formula's. Although its working with single formula.

    =MAX($D$2:$D$6)
    =MAX(INDIRECT("$D$2:$D$"&7-1))
    =MAX(INDIRECT("$D$2:$D$"&ROW()-8)) (i'm on row 14 so subtract -8

    All above formula's all working and now in our formula's ...

    These two working properly

    =OFFSET(INDIRECT(ADDRESS(SUM((MAX(($B$2:$B$6=A9)*($C$2:$C$6=B9)*($A$2:$A$6))=($B$2:$B$6=A9)*($C$2:$C$6=B9)*($A$2:$A$6))*ROW($A$2:$A$6)),1)),0,3)

    =OFFSET(INDIRECT(ADDRESS(SUM((MAX((INDIRECT("$B$2:$B$"&7-1)=A9)*($C$2:$C$6=B9)*($A$2:$A$6))=($B$2:$B$6=A9)*($C$2:$C$6=B9)*($A$2:$A$6))*ROW($A$2:$A$6)),1)),0,3)
    But when i add Row() function it gives error

    =OFFSET(INDIRECT(ADDRESS(SUM((MAX((INDIRECT("$B$2:$B$"&ROW()-3)=A9)*($C$2:$C$6=B9)*($A$2:$A$6))=($B$2:$B$6=A9)*($C$2:$C$6=B9)*($A$2:$A$6))*ROW($A$2:$A$6)),1)),0,3)

    Although there must be some proper reason but i'm jammed here ...
    Attached Files Attached Files
    Last edited by mubashir aziz; 06-11-2009 at 02:10 AM. Reason: Forgot to attach file .......

  9. #9
    Registered User
    Join Date
    06-07-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find value matching multiple text criteria and max date

    Hi guys,

    It's pretty weird, isn't it? I've tried the formula DonkeyOte provided in conjunction with the ROW() formula; It works only in the first portion of the formula. Once you want to add ROW() within the MATCH or MAX function then things start going wrong.

    I've attached a larger sample. As you can see there are some zeros in the column [Native Trx Amount]. These are usually cash transactions. For electronic transactions the actual amount is known an this has been typed to replace the formula in that column.

    The desired result is that the rows with no actual value get calculated based on the last known exchange rate of that currency. I've added some helper columns and also a UDF to determine wether or not the cell contains a value or a formula.

    I get a circular reference when I extend the range to 1000.

    Hope this helps.

    Kind regards,

    Rolf
    Attached Files Attached Files

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find value matching multiple text criteria and max date

    Rolf, in your latest sample that the transactions are in fact sorted by date... you implied this was not the case before... if you can sort by date do so as you can (perhaps) avoid Arrays altogether... we will know later I guess.

    Attached is your file reworked - to avoid circular referencing I revised your formulae in J and created a new column K to return definitive results, and set H such that it always displayed the rate to be used (ie use Real when available else calculate rate)... I've assumed that the rate should be determined by the last rate for a given currency up to and including the given date ... it's also not clear if the rate should be determined not only by currency but also by Trx Type... I would suggest that if you need to post a further sample provide a column of manually entered expected results... this way we can at least try to follow the logic - as is it's quite difficult - this problem may seem obvious to yourself given you're working on it but for those who spend perhaps a max of 5 mins looking at it can be much harder to decipher.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    06-07-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find value matching multiple text criteria and max date

    Hi DonkeyOte,

    The original sheet is sorted on destination. Dates aren't accurately sorted since I can have transactions for another destination while somewhere else. Tickets for instance.

    But your solutions works well and I'll be more than happy to settle with a little bit less accuracy.

    Thanks for both your help on this!

    Rolf

  12. #12
    Registered User
    Join Date
    02-20-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2010
    Posts
    74

    Unhappy Re: Find value matching multiple text criteria and max date

    Hi Guys, I am hoping one of you can also help me do something similiar. I need to fine the last 3 dates (so starting from the bottom of a range) from a range of cells, sum them and then divide by 3 to provide an average. I had the following formula and excel attachment out in the forum but noone had a suggestion.

    =SUMPRODUCT(--('Weekly Vol Pivot'!$B$12:$B$300>=(MAX(IF('Weekly Vol Pivot'!$B$12:$B$300=CONCATENATE(VLOOKUP($D$5,Lookup!$C$17:$D$28,2,FALSE),$D$6),'Weekly Vol Pivot'!$B$12:$B$300))-42)),--(('Weekly Vol Pivot'!$B$12:$B$300= CONCATENATE(VLOOKUP($D$5,Lookup!$C$17:$D$28,2,FALSE),$D$6))),--('Weekly Vol Pivot'!$N$12:$N$300))/6

    Here i was trying to find the last 6 but the concept is the same. I am also attaching my excel workbook. I had to remove all the other formula's and just paste values except for the one cell where the formula is located on the summary sheet, cell d21.
    Attached Files Attached Files

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

    Re: Find value matching multiple text criteria and max date

    krunk, take a moment to read the Forum Rules (link above), they will help you a lot in getting fast answers.

    Your question needs to be posted into a thread of its own where all the forum contributors might see it and respond, whereas this old thread only a couple of people are subscribed to it and "might" respond eventually.

    New threads have the greatest number of possible helpers view them. Thanks.
    _________________
    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!)

+ 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