+ Reply to Thread
Results 1 to 9 of 9

Find last occurrence in an array

  1. #1
    Registered User
    Join Date
    07-22-2014
    Location
    Redlands, California
    MS-Off Ver
    2013
    Posts
    15

    Find last occurrence in an array

    Hello!

    I have a list of dates and account balances. I want to retrieve the balance of the last day of each month. The last day on the list is not always the last day of the month because we don't work every single day, and I don't want to add rows to the spreadsheet. I have added helper columns B, C, D, and H, that could be hidden or deleted if not needed. I was not able to match the years and months with the last day of the month on the list and return the balance, using combinations of index, match, lookup, etc.

    What formula do I write in J2:L13 to return the last balance on each month?

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,895

    Re: Find last occurrence in an array

    This solution adds one more helper column, although it doesn't use column B. F2 and down is populated with the formula:
    Please Login or Register  to view this content.
    Paste the following array formula in J2, press the F2 key then press Ctrl, Shift and Enter simultaneously:
    Please Login or Register  to view this content.
    Pull the fill handle across and then down.
    Let me know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Find last occurrence in an array

    Try this - the formula is array entered (entered using Ctrl-Shift-Enter) - I have removed all of your helper columns since they are not needed, and used this in cell G2, copied to all the other cells in the table.

    =INDEX($B:$B,MAX(IF(YEAR($A2:$A2000)=G$1,IF(MONTH($A2:$A2000)=$E2,ROW($A2:$A2000)))))
    Attached Files Attached Files
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Find last occurrence in an array

    Hi Abisay,

    Enter this formula in J2, copy across and down

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Find last occurrence in an array

    Your formula would return the largest balance for the month and year rather than the balance on the last recorded day for that period.

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Find last occurrence in an array

    I guess, I missed this part

    array formula in J2 and copy across and down

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    ***Array formula must be entered by using key combination of CTRL+SHIFT+ENTER and not just ENTER

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Find last occurrence in an array

    Or this regular formula

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Find last occurrence in an array

    Nice formula - and without the helper columns, it could be this: columns B,C, and D can then be deleted:

    =IFERROR(LOOKUP(2,1/(MONTH($A$2:$A$561)&YEAR($A$2:$A$561)=$H2&J$1),$E$2:$E$561),"")

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Find last occurrence in an array

    Quote Originally Posted by Bernie Deitrick View Post
    Nice formula - and without the helper columns, it could be this: columns B,C, and D can then be deleted:

    =IFERROR(LOOKUP(2,1/(MONTH($A$2:$A$561)&YEAR($A$2:$A$561)=$H2&J$1),$E$2:$E$561),"")
    I just used the OP's original sheet.

+ 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. Replies: 2
    Last Post: 02-06-2015, 11:23 AM
  2. Find each occurrence in a column and do for each occurrence
    By jfoerch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2014, 12:29 PM
  3. [SOLVED] find nth occurrence in array
    By ccsmith in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-05-2014, 02:56 PM
  4. [SOLVED] Create 1-col array identifying occurrence count in a 1-col array
    By empsall in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2013, 12:50 PM
  5. Row of first occurrence in an array?
    By blooper in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-13-2013, 01:56 PM
  6. Find Second Occurrence of Match in Array
    By StevieD in forum Excel General
    Replies: 10
    Last Post: 04-25-2011, 02:27 PM
  7. return row for nth occurrence of text in array
    By Greg777 in forum Excel General
    Replies: 3
    Last Post: 11-03-2010, 12:37 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