Return 2nd most recent value

csliger931

New Member
Joined
Jul 22, 2020
Messages
21
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Newbie here. I am looking for a function that will return the 2nd most recent value for a specified parameter. For example, lets say I am trying to calculate the Cycle Rate for certain Wells at a landfill. In order to do this, I need to take the most recent cycle count (Xn), subtract the 2nd most recent cycle count (Xn-1), and divide all of that by the elapsed time (Daten - Daten-1). The problem is that I have a massive amount of dates/values, and a lot of wells. So, if I want to calculate the cycle rate for Well "A", I don't know a formula for looking up the second most recent cycle count
(Xn-1) for A. I'm pretty sure I can use the MATCH INDEX function for returning the most recent cycle count for Well "A", but I'm not sure about 2nd most recent. Any tips/helps would be appreciated. I am not against doing a Macro, but my Macro skills are non-existent, so I would prefer a function/nested function if there is one. Thanks!!!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the forum, it will help to get an answer if you provide a sample of your data and show what results you are after.
Use the XL2BB option to post the sample data.
 
Upvote 0
Unfortunately our work Administrator has blocked add-ins to Excel, but I have attached an image with the values that I want highlighted. I've also included a table below (the desired values that I want the function to retrieve are in the last column...I want it to pull the 2nd most recent Cycle Count for the specified well ( 3 for LW-A and 6 for LW-B) ). Thanks!
WELLDATECYCLE COUNTWELL2ND MOST RECENT CYCLE COUNT
LW-A7/16/20
3

LW-B

7/12/20

6
LW-A3

LW-A

7/12/20

1
LW-B6

LW-B

7/15/20

7

LW-C

7/17/20

9

LW-A

7/18/20

2
 

Attachments

  • MrExcel.JPG
    MrExcel.JPG
    94 KB · Views: 7
Upvote 0
Try
=INDEX($D$4:$D$9,MATCH(AGGREGATE(14,6,($C$4:$C$9)/($B$4:$B$9=$G4),2),$C$4:$C$9,0))

1595446981675.png
 
Upvote 0
Ok, this appears to work

=INDEX($D$10:$D$17,MATCH($G7&AGGREGATE(14,6,($C$10:$C$17)/($B$10:$B$17=$G7),2),$B$10:$B$17&$C$10:$C$17,0))

Enter as an array using Ctrl, Shift & Enter

1595447440097.png
 
Upvote 0
This does the same but is a non array formula, pretty sure there is a better solution, but it's late :)

=AGGREGATE(14,6,($D$10:$D$17)/($B$10:$B$17=G7)/($C$10:$C$17=AGGREGATE(14,6,($C$10:$C$17)/($B$10:$B$17=$G7),2)),1)

Just so you know, the 2 in red is what tells it to return the 2nd Largest Value.
 
Upvote 0
Gaz you are the MAN!! That worked great! I wasn't even aware of an "Aggregate" function (I know, I'm a novice...), but I'm definitely going to have to look into it. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top