Forum Discussion

Adam08320's avatar
Adam08320
Copper Contributor
Jul 07, 2024

Return Value Based on Latest Date

Hello, I'm trying to return a value based on the latest date which has duplicates

For example...

DateBalance
01/01/24£100
02/01/24£120
01/02/24£200
01/03/24£210
01/03/24£220
01/03/24£230

Date DD/MM format
As there can be multiple transactions on the same day
So I'm trying to return the last value £230
I've looked online but couldn't find a clear enough solution
Office Pro Plus 2021
Please advise & thank you for your time

    • Adam08320's avatar
      Adam08320
      Copper Contributor
      Sorry I should have mentioned, I don't want to use the latest date as criteria in your D2 preferably not an array either
  • djclements's avatar
    djclements
    Bronze Contributor

    Adam08320 Here's a couple of options using XLOOKUP with the optional [search_mode] argument set to -1 (last-to-first):

     

    =LET(
        data, A2:B7,
        dates, INDEX(data,, 1),
        latest_duplicate, MAX(FILTER(dates, COUNTIF(dates, dates) > 1, 0)),
        XLOOKUP(latest_duplicate, dates, INDEX(data,, 2), 0,, -1)
    )

     

    - OR -

     

    =LET(
        data, A2:B7,
        dates, INDEX(data,, 1),
        only_once, UNIQUE(dates,, 1),
        latest_duplicate, IF(ISNUMBER(ROWS(only_once)), MAX(FILTER(dates, ISNA(XMATCH(dates, only_once)), 0)), MAX(dates)),
        XLOOKUP(latest_duplicate, dates, INDEX(data,, 2), 0,, -1)
    )

     

    Adjust the data range as needed (assuming Date is column 1 and Balance is column 2).

     

    Based on my understanding of your description, these formulas will return the "last value" for the "latest date which has duplicates", so dates appearing only once will be ignored.

     

    According to Microsoft Support documentation found online, all of the functions used in the above methods should be compatible with Excel 2021.

      • djclements's avatar
        djclements
        Bronze Contributor

        Adam08320 Unfortunately, it's not very clear what you're asking (even less so now). Are you just trying to return the last value in the Balance column? So, if Date was in column A and Balance was in column B, would any of the following do what you what?

         

        =INDEX(FILTER(B:B, NOT(ISBLANK(A:A))), COUNTA(A:A))
        
        =INDEX(B:B, XMATCH(, A:A) - 1)
        
        =XLOOKUP(MAX(A:A), A:A, B:B,,, -1)

Resources