Index Match to return 2nd value

Mighty_Mitchell

New Member
Joined
May 15, 2019
Messages
11
I am trying to populate a table using formulae from a tab containing the data.
I have completed this for the latest set of information I require, but would also like to add a column to show the result previous to this. So we have the 2 most recent results appearing in the table.

I am happy with the formula I have used to obtain the 'most recent' detail, but I am struggling to complete the formula to show me the '2nd most recent' detail.

Most Recent: =IFERROR(INDEX(SpotcheckDatabase,MATCH(B7,SpotcheckDatabaseDriverName,0),6),"")

What do I need to do to change this formula to show me the second most recent?

Thank you in advance
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this:
 
Upvote 0
Try this:
Thank you,

I've already looked at this thread and still can't get it to work!

I've tried to use this formula
=INDEX(SpotcheckDatabase,SMALL(IF(SpotcheckDatabaseDriverName='Spot Check Report'!B7,ROW(CheckDate)),2))
This returned either #NUM! or #REF! :(

Spotcheckdatabase shows all my data
SpotcheckdatabaseDriverName is a column in my spotcheckdatabase table
Check date is a column in my spotcheckdatabase table
Spot Check Report B7 is the name of the driver I wish to use as a Match field.

Thank you
 
Upvote 0
See if this does what you want to retrieve the second value
=INDEX(SpotcheckDatabase,AGGREGATE(15,6,(ROW(SpotcheckDatabaseDriverName)-ROW(INDEX(SpotcheckDatabaseDriverName,1))+1)/(SpotcheckDatabaseDriverName='Spot Check Report'!B7),2),6)
 
Upvote 0
Unfortunately it has returned #NUM!
That would happen if 'Spot Check Report'!B7 did not occur at least twice in SpotcheckDatabaseDriverName (though there could also be other reasons)

If that is not the issue then perhaps you need to give us a small set of dummy data to work with as we are guessing just what it is like and how it is laid out. My signature block below has help with that.
 
Upvote 0
See if this example helps - getting John's 1st and 2nd scores

Book1
ABCDEF
1NameScoreNameScoreResult
2Anthony10John19
3John9John27
4Mary11
5Anthony12
6John7
7Mary8
8Anthony9
9John8
10Mary9
Plan1
Cell Formulas
RangeFormula
F2:F3F2=INDEX(B$2:B$10,AGGREGATE(15,6,(ROW(B$2:B$10)-ROW(B$2)+1)/(A$2:A$10=D2),E2))
 
Upvote 0
SpotCheckDataBase.png
SpotcheckTable.png



The first image is my table.
The entire table is From cell A:AV (all rows down) is named SpotCheckDataBase
This table is on a tab named Spot Check Database
Column F is named CheckDate and Column G is named Result

The second image is the table I am populating. This is on a separate tab named Spot Check Report.
I have already populated the date of latest spot check and result by using the below formulae.
Latest Spot Check Date: =IFERROR(INDEX(SpotcheckDatabase,MATCH(B7,SpotcheckDatabaseDriverName,0),6),"")
Latest Result: =IFERROR(INDEX(SpotcheckDatabase,MATCH($B7,SpotcheckDatabaseDriverName,0),7),"")
I am struggling with the formula to enter into the date of previous spot check and result of previous spot checks.


I don't know what I am doing wrong. It's so frustrating!
Thank goodness for Mr Excel!
 
Upvote 0
Try something like this - i used ranges instead of table references

Data in Sheet1
Book1
ABCDEFG
1DriverInspector VehicleTrailerLocationCheck DateResult
2CarolePeterFTE5000AVR 1Birmingham01/11/2019Pass
3JaquiPeterFTE6000AVR15Manchester20/10/2019Pass
4JohnPeterFTE7000N/ALondon10/10/2019Pass
5CarolePeterFTE5000AVR 1Sheffield05/10/2019Fail
6JohnPeterFTE7000N/ASouthhampton16/09/2019Fail
7CarolePeterFTE5000AVR 1Birmingham09/09/2019Fail
8JaquiPeterFTE6000AVR15Leeds01/09/2019Pass
Sheet1


Results in Sheet2
Book1
BCDEFGH
6DriverDate LatestSpot LatestDaysDate PreviousResult PreviousDays Between
7Carole01/11/2019Pass05/10/2019Fail27
8Jaqui20/10/2019Pass01/09/2019Pass49
9John10/10/2019Pass16/09/2019Fail24
Sheet2
Cell Formulas
RangeFormula
C7:C9C7=INDEX(Sheet1!F$2:F$8,MATCH(B7,Sheet1!A$2:A$8,0))
D7:D9D7=INDEX(Sheet1!G$2:G$8,MATCH(B7,Sheet1!A$2:A$8,0))
F7:F9F7=INDEX(Sheet1!F$2:F$8,AGGREGATE(15,6,(ROW(Sheet1!A$2:A$8)-ROW(Sheet1!A$2)+1)/(Sheet1!A$2:A$8=B7),2))
G7:G9G7=INDEX(Sheet1!G$2:G$8,AGGREGATE(15,6,(ROW(Sheet1!A$2:A$8)-ROW(Sheet1!A$2)+1)/(Sheet1!A$2:A$8=B7),2))
H7:H9H7=C7-F7


Hope this helps

M.
 
Upvote 0
Thanks for the additional sample data but for the future, you will get much better response if you show data that can be copied, rather than just an image from which helpers would have to manually type the data to test. Most helpers are not interested in manually typing out the sample data ;) Again, my signature block below has help with that.

I have assumed that a driver will not take the test twice on the same day. If that can happen the formulas would need adjusting.
Note that I have provided an alternative formula for C7 & D7 as well.

Book1
BCDEF
7Carole1/11/2019Pass5/10/2019Fail
Spot Check Report
Cell Formulas
RangeFormula
C7C7=IFERROR(AGGREGATE(14,6,CheckDate/(SpotCheckDatabaseDriverName=B7),1),"")
D7D7=IF(C7="","",INDEX(Result,AGGREGATE(15,6,(ROW(Result)-ROW(INDEX(Result,1))+1)/((SpotCheckDatabaseDriverName=B7)*(CheckDate=C7)),1)))
E7E7=IFERROR(AGGREGATE(14,6,CheckDate/(SpotCheckDatabaseDriverName=B7),2),"")
F7F7=IF(E7="","",INDEX(Result,AGGREGATE(15,6,(ROW(Result)-ROW(INDEX(Result,1))+1)/((SpotCheckDatabaseDriverName=B7)*(CheckDate=E7)),1)))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

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