Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find last ocurrence based on match criteria

I have a Google Sheets that I use to run tests for an app I developed. The spreadsheet has two sheets, on the first ("Runs" sheet) I put the dates (in DD/MM/YYYY format), test id and result for the tests:

---------------------------------|
|Date        | test id  | Result
|--------------------------------|
|12/10/2014  | 1        | Passed |
|12/10/2014  | 2        | Passed |
|12/10/2014  | 3        | Passed |
|03/11/2014  | 4        | Passed |
|05/11/2014  | 1        | Failed |    
----------------------------------

On the second sheet I want to have the list of all the tests, and when was the last time they were executed, and also the Results for them. This is the expected output in "Tests" sheet:

-----------------------------------|
|test id     | Last run   | Result
|----------------------------------|
|1           | 05/11/2014 | Failed |
|2           | 12/10/2014 | Passed |
|3           | 12/10/2014 | Passed |
|4           | 03/11/2014 | Passed |
|5           |            |        |    
------------------------------------

My problem is that I don't know how to get the "last run" for a test. I used the following formula:

=IF(ISNA(INDEX(Runs!A$3:A$9992, MATCH(A5, Runs!B$3:B$9992, 0))), "", INDEX(Runs!A$3:A$9992, MATCH(A5, Runs!B$3:B$9992, 0)))

But that only returns the first match for the test id, and not the last one. So, this is the output I'm currently seeing in "Tests" sheet:

-----------------------------------|
|test id     | Last run   | Result
|----------------------------------|
|1           | 12/10/2014 | Passed |
|2           | 12/10/2014 | Passed |
|3           | 12/10/2014 | Passed |
|4           | 03/11/2014 | Passed |
|5           |            |        |    
------------------------------------

Can someone help me to change the formula to make it return the last match, like the expected output?

like image 736
arlistan Avatar asked Nov 04 '14 16:11

arlistan


1 Answers

'Test'!B1 : =max(filter(Runs!A:A,Runs!B:B=A1)) - to find out the last date for a given test id (cell A1)

'Test'!C1 : =filter(Runs!C:C,Runs!B:B=A1,Runs!A:A=B1) - to find out the result corresponding to that test on that date.

Copy down for the rest of tests

like image 161
user3616725 Avatar answered Sep 22 '22 03:09

user3616725