Index & Match excluding duplicates

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
610
Office Version
  1. 365
Platform
  1. Windows
Hello,
My goal is to pull the correct number in Column B if A:A matches D1 but exclude duplicates in Column B. D1 has Data validation and will change on users requests. The correct results are listed in Column E.

I tried using
{=INDEX($B$2:$B$13,MATCH(0,COUNTIF($F$1:F1,$B$2:$B$13),0))} but not sure how to add another Match to D1.

I also thought I could use the Frequency function but couldn’t build it correctly.

{=IF(SUM(IF(FREQUENCY(IF($A$2:$A$13=$D$1,$B$2:$B$13),$B$2:$B$13)>0,1))>=COLUMNS($F$1:F$1),INDEX($B$2:$B$13,SMALL(IF(FREQUENCY(IF($A$2:$A$13=$D$1,$B$2:$B$13),$B$2:$B$13),ROW($A$2:$A$13)-ROW($A$2)+1),COLUMNS($F$1:F$1))),"")}

Any help is appreciated.
Excel Workbook
ABCDE
1RegDistMidS
2MidS11
3MidS12
4MidS2#N/A
5MidS2#N/A
6North3#N/A
7North66
8North66
9North7
10East4
11East4
12East4
13East5
Sheet3
Excel 2010
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,

in E2 try:
Code:
=IF(ROWS($E$2:$E2) > SUM(SIGN(FREQUENCY(IF($A$2:$A$21=$D$1,IF(ISNUMBER($B$2:$B$21),$B$2:$B$21)),$B$2:$B$21))), "",
MIN(IF(COUNTIF($E$1:$E1,$B$2:$B$21),FALSE,IF($A$2:$A$21=$D$1,IF(ISNUMBER($B$2:$B$21),$B$2:$B$21)))))
validate with Ctrl+Shift+Enter (array formula) and copy down as necessary

Regards
XLearner
 
Upvote 0
[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][td]
D​
[/td][td]
E​
[/td][/tr]
[tr][td]
1​
[/td][td]Reg[/td][td]Dist[/td][td][/td][td][/td][td]MidS[/td][/tr]


[tr][td]
2​
[/td][td]MidS[/td][td]
1
[/td][td][/td][td][/td][td]
1​
[/td][/tr]


[tr][td]
3​
[/td][td]MidS[/td][td]
1
[/td][td][/td][td][/td][td]
2​
[/td][/tr]


[tr][td]
4​
[/td][td]MidS[/td][td]
2
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
5​
[/td][td]MidS[/td][td]
2
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
6​
[/td][td]North[/td][td]
3
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
7​
[/td][td]North[/td][td]
66
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
8​
[/td][td]North[/td][td]
66
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
9​
[/td][td]North[/td][td]
7
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
10​
[/td][td]East[/td][td]
4
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
11​
[/td][td]East[/td][td]
4
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
12​
[/td][td]East[/td][td]
4
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
13​
[/td][td]East[/td][td]
5
[/td][td][/td][td][/td][td][/td][/tr]
[/table]


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

=IFERROR(1/(1/MIN(IF($A$2:$A$13=$E$1,IF(ISNUMBER(MATCH($B$2:$B$13,$E$1:E1,0)),"",$B$2:$B$13)))),"")

The set up assumes that 0 does not appear as a dist value.
 
Upvote 0
Hello Aladin,
I found something very odd with your formula. When certain numbers appear in Column D, the formula stops at specific numbers and repeats them down the column and doesn't catch some of the other numbers. For example, numbers 197, 99, 98, 239, 24 & 117 for some reason create havoc with the formula. I thought maybe I had some kind of spacing in the text or number cells but that wasn't the case. I also checked to make sure none of the numbers were stored as text. I just thought it was very odd and I don't see what maybe causing it.

Anyway, the formula xLearner provided works.
 
Upvote 0
Hello Aladin,
I found something very odd with your formula. When certain numbers appear in Column D, the formula stops at specific numbers and repeats them down the column and doesn't catch some of the other numbers. For example, numbers 197, 99, 98, 239, 24 & 117 for some reason create havoc with the formula. I thought maybe I had some kind of spacing in the text or number cells but that wasn't the case. I also checked to make sure none of the numbers were stored as text. I just thought it was very odd and I don't see what maybe causing it.

Anyway, the formula xLearner provided works.

Would you post that sample as it is not a good idea to give up by far an efficient formula?
 
Upvote 0
Here's a sample
Excel Workbook
ABCDEFGH
1RegDistCEN
2Cen3838
3Cen3848
4Cen3865
5Cen4880
6Cen4898
7Cen4898
8Cen6598
9Cen6598
10Cen6598
11Cen8098
12Cen9898
13Cen9898
14Cen9898
15Cen9898
16Cen145
17Cen145
18Cen145
19Cen150
20Cen150
Test
Excel 2010
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
 
Upvote 0
Here's a sample

Test[TABLE="class: html-maker-worksheet"]
<thead>[TR]
[TH][/TH]
[TH]A[/TH]
[TH]B[/TH]
[TH]C[/TH]
[TH]D[/TH]
[TH]E[/TH]
[TH]F[/TH]
[TH]G[/TH]
[TH]H[/TH]
[/TR]
</thead><tbody>[TR]
[TH]1[/TH]
[TD]Reg[/TD]
[TD]Dist[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: center"]CEN[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH]2[/TH]
[TD]Cen[/TD]
[TD="align: right"]38[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]38[/TD]
[/TR]
[TR]
[TH]3[/TH]
[TD]Cen[/TD]
[TD="align: right"]38[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]48[/TD]
[/TR]
[TR]
[TH]4[/TH]
[TD]Cen[/TD]
[TD="align: right"]38[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]65[/TD]
[/TR]
[TR]
[TH]5[/TH]
[TD]Cen[/TD]
[TD="align: right"]48[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]80[/TD]
[/TR]
[TR]
[TH]6[/TH]
[TD]Cen[/TD]
[TD="align: right"]48[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]7[/TH]
[TD]Cen[/TD]
[TD="align: right"]48[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]8[/TH]
[TD]Cen[/TD]
[TD="align: right"]65[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]9[/TH]
[TD]Cen[/TD]
[TD="align: right"]65[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]10[/TH]
[TD]Cen[/TD]
[TD="align: right"]65[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]11[/TH]
[TD]Cen[/TD]
[TD="align: right"]80[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]12[/TH]
[TD]Cen[/TD]
[TD="align: right"]98[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]13[/TH]
[TD]Cen[/TD]
[TD="align: right"]98[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]14[/TH]
[TD]Cen[/TD]
[TD="align: right"]98[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]15[/TH]
[TD]Cen[/TD]
[TD="align: right"]98[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TH]16[/TH]
[TD]Cen[/TD]
[TD="align: right"]145[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH]17[/TH]
[TD]Cen[/TD]
[TD="align: right"]145[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH]18[/TH]
[TD]Cen[/TD]
[TD="align: right"]145[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH]19[/TH]
[TD]Cen[/TD]
[TD="align: right"]150[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH]20[/TH]
[TD]Cen[/TD]
[TD="align: right"]150[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[...]

=IFERROR(1/(1/MIN(IF($A$2:$A$20=$F$1,IF(ISNUMBER(MATCH($B$2:$B$20,$H$1:H1,0)),"",$B$2:$B$20)))),"")

Thanks. And grateful to see a conclusive test that the idiom IFERROR(1/(1/X),"") fails.

The reason is seemingly the result of the division 1/X that exceeds the number precision of 15 digits (see "limits" in help).

Again, the conclusion is that the idiom must be abandoned.

A different take regarding the problem worded in your initial post:

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][td]
D​
[/td][td]
E​
[/td][/tr]
[tr][td]
1​
[/td][td]Reg[/td][td]Dist[/td][td][/td][td][/td][td]
7​
[/td][/tr]


[tr][td]
2​
[/td][td]Cen[/td][td]
38
[/td][td][/td][td][/td][td]Cen[/td][/tr]


[tr][td]
3​
[/td][td]Cen[/td][td]
38
[/td][td][/td][td][/td][td]
38​
[/td][/tr]


[tr][td]
4​
[/td][td]Cen[/td][td]
38
[/td][td][/td][td][/td][td]
48​
[/td][/tr]


[tr][td]
5​
[/td][td]Cen[/td][td]
48
[/td][td][/td][td][/td][td]
65​
[/td][/tr]


[tr][td]
6​
[/td][td]Cen[/td][td]
48
[/td][td][/td][td][/td][td]
80​
[/td][/tr]


[tr][td]
7​
[/td][td]Cen[/td][td]
48
[/td][td][/td][td][/td][td]
98​
[/td][/tr]


[tr][td]
8​
[/td][td]Cen[/td][td]
65
[/td][td][/td][td][/td][td]
145​
[/td][/tr]


[tr][td]
9​
[/td][td]Cen[/td][td]
65
[/td][td][/td][td][/td][td]
150​
[/td][/tr]


[tr][td]
10​
[/td][td]Cen[/td][td]
65
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
11​
[/td][td]Cen[/td][td]
80
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
12​
[/td][td]Cen[/td][td]
98
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
13​
[/td][td]Cen[/td][td]
98
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
14​
[/td][td]Cen[/td][td]
98
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
15​
[/td][td]Cen[/td][td]
98
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
16​
[/td][td]Cen[/td][td]
145
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
17​
[/td][td]Cen[/td][td]
145
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
18​
[/td][td]Cen[/td][td]
145
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
19​
[/td][td]Cen[/td][td]
150
[/td][td][/td][td][/td][td][/td][/tr]


[tr][td]
20​
[/td][td]Cen[/td][td]
150
[/td][td][/td][td][/td][td][/td][/tr]
[/table]


In E1 control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(A2:A20=E2,B2:B20),B2:B20),1))

In E3 control+shift+enter and copy down:

=IF(ROWS($E$3:E3)>$E$1,"",MIN(IF($A$2:$A$20=$E$2,IF(ISNUMBER(MATCH($B$2:$B$20,$E$2:E2,0)),"",$B$2:$B$20))))
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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