+ Reply to Thread
Results 1 to 11 of 11

Retrieve second last, third last, or Nth value from a column

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Retrieve second last, third last, or Nth value from a column

    Currently I have data in Range (Column) Q36:Q65 which is derived using combination of formulas If Index Max Match etc., and typically it would have zero value towards end of column. I mean, say Q36 to Q46 or so would have formula derived values, but Q47 onwards till Q65 formula would have returned "0" value. (this would vary each time zero value from Q47 to Q65, say from Q47, Q52, Q60 till last Q65)

    Currently I retrieve last non zero value, using following formula

    =((LOOKUP(2,1/($Q$36:$Q$65<>0),$Q$36:$Q$65)))

    But, what i now seek is to derive 3rd or 5th or 7th value from last non zero value. How to change above formula or use alternative formula in different cell to get 3rd last, 5th last, or nth value from bottom (non-zero) value.

    Sample looks like this
    http://imgur.com/a/0MhJE

    Screenshot_1.jpg

    Thanks
    Attached Files Attached Files
    Last edited by analystbank; 12-15-2016 at 05:48 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,188

    Re: Retrieve second last, third last, or Nth value from a column

    Based on your sample data, try this for the third last:

    =INDEX($Q$36:$Q$65,MATCH(0,$Q$36:$Q$65,0)-4,0)

    The number in red needs to be one higher than the match you are looking for. This will not work if there are 0 values earlier in the range, however.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,920

    Re: Retrieve second last, third last, or Nth value from a column

    Try

    =INDEX($Q$36:$Q$65,COUNTIF($Q$36:$Q$65,">"&0)-$S$1+1)

    where S1 = 3 for 3rd from bottom, 5 for 5th from bottom etc

    Assumes non-zero cells are contiguous.

  4. #4
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Retrieve second last, third last, or Nth value from a column

    Quote Originally Posted by JohnTopley View Post
    Try

    =INDEX($Q$36:$Q$65,COUNTIF($Q$36:$Q$65,">"&0)-$S$1+1)

    where S1 = 3 for 3rd from bottom, 5 for 5th from bottom etc

    Assumes non-zero cells are contiguous.
    Thanks for your reply. Are you referring to the highlighted value as S1?

    I am getting 0 value if i replace it to S3/S5

    Is it Array formula?

  5. #5
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Retrieve second last, third last, or Nth value from a column

    Quote Originally Posted by AliGW View Post
    Based on your sample data, try this for the third last:

    =INDEX($Q$36:$Q$65,MATCH(0,$Q$36:$Q$65,0)-4,0)

    The number in red needs to be one higher than the match you are looking for. This will not work if there are 0 values earlier in the range, however.
    This worked. Thanks. But just i wonder, why it gives result, when u say, This will not work if there are 0 values earlier in the range, however., when i do have 0 value (not earlier), but later in range. !!!

    Is there any better way to ignore, zero value altogether and just retrieve last nth from last non-zero value?

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,188

    Re: Retrieve second last, third last, or Nth value from a column

    It works because it is indexing the first blank value it finds in the range (using the MATCH function to establish the row). Once it finds that, we take 4 from the row value to find the correct row for your third to last non-blank value. If there were a 0 value in the middle of your range, it would use that as its starting point, and return an incorrect result.

  7. #7
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Retrieve second last, third last, or Nth value from a column

    Quote Originally Posted by AliGW View Post
    It works because ..................................If there were a 0 value in the middle of your range, it would use that as its starting point, and return an incorrect result.
    How nice of you to have answered my all queries. Thanks Board.

    Merry Christmas and Wish you a cheerful, new Year.

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,920

    Re: Retrieve second last, third last, or Nth value from a column

    $S$1 is the CELL reference: if you put 3 in this cell (S1) you will next the 3rd from bottom value. If put in 5 you will get the 5th From bottom.
    Attached Files Attached Files

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,188

    Re: Retrieve second last, third last, or Nth value from a column

    Glad to have helped! Merry Christmas!

  10. #10
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Retrieve second last, third last, or Nth value from a column

    Quote Originally Posted by analystbank View Post
    Is there any better way to ignore, zero value altogether and just retrieve last nth from last non-zero value?
    This solution is insensitive to zeroes among the values:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    It's an array formula, it has to be entered with Ctrl + Shift + Enter.
    Attached Files Attached Files
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  11. #11
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Retrieve second last, third last, or Nth value from a column

    Thanks JohnTopley, and Jacc.

    @John, i just realised that you use S1, as driver/key/trigger cell to get the desire result.

+ 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. Query column of PC names to retrieve remote mac addresses in another column
    By CME1212 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-13-2016, 04:48 PM
  2. Retrieve Column Headers Dynamically - Based on column Values
    By akshaysudhir in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-12-2016, 05:42 AM
  3. Need Formula to Match Text In a column And Retrieve adjacent column value
    By excel_joel in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-06-2014, 02:08 AM
  4. Replies: 1
    Last Post: 11-22-2013, 05:56 AM
  5. can column retrieve information based on another sheet's column
    By tanglin10 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2013, 08:12 AM
  6. [SOLVED] Retrieve data from Column A based on a 1st negative value from Column B
    By edram95 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-16-2012, 12:37 PM
  7. Replies: 11
    Last Post: 05-22-2012, 10:56 AM

Tags for this Thread

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