简体   繁体   中英

Excel Find Nth Instance of Multiple Criteria

I have 3 columns of data. Col A contains Names, Col B contains a client ID, Col C contains a date.

I'm trying to figure out how to write a formula that will find the top 2 and top 3 instances of a specific Name in Col A and client ID in Col B and return the value in Col C.

Trying to avoid using VBA, but not sure if this is doable.

So for example data looks like this and I would want to return that Sam dealt with Client ABC the 2nd time around on 12/16.

Sam ABC 12/3

Adam XYZ 12/5

John DEF 12/9

Sam ABC 12/16

Adam HIJ 12/18

Let me see if I understood your need. Correct me if I'm wrong.

You want to be able to inform a Name and a Client ID and have Excel tell you the last 3 occurrences of that combination?

By "top 2 and top 3 instances of a specific name" I'm assuming you mean the top 2 and 3 dates found for that specific name and ID.

If so, try this:

Supposing you have your example data table starting at Cell A1 and ending at Cell C6 (including column headers) and that you'll enter the name in F1 and Client ID on F2

A B C
1 Name Client ID Date
2 Sam ABC 12/3
3 Adam XYZ 12/5
4 John DEF 12/9
5 Sam ABC 12/16
6 Adam HIJ 12/18

Type this formula where you want to return the date of the last occurrence:

=IFERROR(LARGE(IF($A$2:$A$6=$F$1,IF($B$2:$B$6=$F$2,$C$2:$C$6)),1),"-")  

This should be entered as an , so don't forget to press CTRL + SHIFT + ENTER or it'll not work. 输入,所以不要忘记按CTRL + SHIFT + ENTER否则将不起作用。

To bring the 2nd last occurrence on another cell, just copy and paste the formula and change the number 1 to 2 (as indicated below):

=IFERROR(LARGE(IF($A$2:$A$6=$F$1,IF($B$2:$B$6=$F$2,$C$2:$C$6)),),"-")

If you typed 'Sam' on F1 and 'ABC' on F2, this formula would return '12/16' as the last occurrence, '12/3' as the 2nd last occurrence and a dash (-) as the 3rd last occurrence, since there isn't one.

Of course, you'll have to adjust the ranges and other cell references accordingly in your real data set.

Hope this helps.

Assuming

  • your headers are in A1:C1
  • your data starts from A3 (yes, not A2)
  • You enter the name in G2 & Client ID in G3 & you want the list of dates starting from G5

Enter these formula/values:

  • A2: =G2
  • B2: =G3
  • C2: =0
  • G5: =IFERROR(INDEX(($A$2:$A$500=$G$2)*($B$2:$B$500=$G$3)*($C$2:C$500),MATCH(0,COUNTIF($G$4:G4,($A$2:$A$500=$G$2)*($B$2:$B$500=$G$3)*($C$2:C$500)),0)),"End")

(Formula in G5 is an array formula; confirm this with Ctrl+Shift+Enter)

Drag the formula in G5 down until you see 'End'

Value in cell G5 will always be 0 or '1/0' based on your formatting.

The list of dates corresponding to the name & client ID combination will start from G6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM