Index match and unique values

kurigami

New Member
Joined
Aug 18, 2016
Messages
15
Hi everyone. I've been racking my brain with this one for a while now and am hoping someone can help me to understand what change I need to make to return unique values. I have a workbook with two worksheets. One worksheet contains a list of every employee in my local organization, and in the next column has the supervisor name for each employee (looks like this):

Column AColumn B

<tbody>
</tbody>
Employee 1Supervisor 1
Employee 2Supervisor 1
Employee 3Supervisor 2
Employee 4Supervisor 2
Employee 5Supervisor 3

<tbody>
</tbody>

This continues for up to 2000 rows.
On the other worksheet, I am trying to pull the employee list for each supervisor (to be used as a drop down later). My desired outcome would display the employee name for each matching supervisor (where the supervisor's name is provided in Row 1). It would look like this:

Column AColumn BColumn C

<tbody>
</tbody>
Supervisor 1Supervisor 2Supervisor 3
Employee 1Employee 3Employee 5
Employee 2Employee 4

<tbody>
</tbody>

I've started with an index to match the supervisor name with the employee name, however, I can not for the life of me figure out how to use the subarray to only return unique values. Here's my formula that I'm entering into cells A2:C3 for the desired outcome above:

{=INDEX(TCS!$A$2:$A$2000,MATCH(A$1,TCS!$B$2:$B$2000,0))}

The formula works to pull an employee's name that matches the above supervisor name, however, it does not continue beyond the first employee that matches. Instead, I get a repeat of Employee 1 over and over again, instead of it finding the next employee that matches the Supervisor name. I know there should be a CountIF somewhere in here to make this work, but can't figure it out.

Any help would be appreciated :)
Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You can use a formula like this.

Code:
=IFERROR(INDEX($A$1:$A$5,AGGREGATE(15,6,ROW($A$1:$A$5)-ROW($A$1)+1/($B$1:$B$5=E$1),ROWS($A$1:A1))), "")

Employee data goes from A1 to A5, Supervisor Data goes from B1 to B5 and then Supervisor 1 is in E1, Supervisor 2 is in F1, and Supervisor 3 is in G1.
 
Upvote 0
Thanks so much Goalman! Once I added in the worksheet references it worked perfectly, however, I'd like to understand this better so I can use it in the future with other sheets. Can you help me to understand the other functions (Aggregate and Row/Rows)? I'm trying to read up on them and not getting very far.

You can use a formula like this.

Code:
=IFERROR(INDEX($A$1:$A$5,AGGREGATE(15,6,ROW($A$1:$A$5)-ROW($A$1)+1/($B$1:$B$5=E$1),ROWS($A$1:A1))), "")

Employee data goes from A1 to A5, Supervisor Data goes from B1 to B5 and then Supervisor 1 is in E1, Supervisor 2 is in F1, and Supervisor 3 is in G1.
 
Upvote 0
Row\Col
A​
B​
C​
D​
E​
F​
1​
2​
2​
1​
2​
Employee 1 Supervisor 1 Supervisor 1 Supervisor 2 Supervisor 3
3​
Employee 2 Supervisor 1 Employee 1 Employee 3 Employee 5
4​
Employee 3 Supervisor 2 Employee 2 Employee 4
5​
Employee 4 Supervisor 2
6​
Employee 5 Supervisor 3
7​

In D1 just enter and copy across:

=COUNTIFS($B$2:$B$6,D$2)

In D3 control+shift+enter, not just enter, copy across, and down:

=IF(ROWS(D$3:D3)<=D$1,INDEX($A$2:$A$6,SMALL(IF($B$2:$B$6=D$2,ROW($A$2:$A$6)-ROW($A$2)+1),ROWS(D$3:D3))),"")

You can define SUPERVISOR1 in Name Manager as referring to:

=OFFSET(Sheet1!$D$3,0,0,Sheet1!$D$1)

Adjust the sheet name to suit.
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

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