## Unique distinct records sorted based on count or frequency

How can you use large with multiple criteria?? Example looking for top 5 of a list based on name, state and city..

The formula entered in cell E3 extracts unique distinct records sorted based on frequency or count.

Array formula in cell E3:

#### How to enter an array formula

- Copy above array formula.
- Select cell E3
- Paste array formula to cell E3
- Press and hold CTRL + SHIFT simultaneously.
- Press Enter once.
- Release all keys.

If you did it right the formula is now enclosed with curly brackets, don't enter these characters yourself. They appear automatically if you followed the above steps.

#### How to copy array formula and paste to remaining cells

- Select cell E3
- Copy cell (not formula). (CTRL + c)
- Select cell range F3:G3
- Paste to cell range F3:G3. (CTRL + v)
- Select cell range E3:G3.
- Copy cells (not formulas). (CTRL + c)
- Select cell range E4:G9.
- Paste to cell range E4:G9. (CTRL + v)

Regular formula in cell H3:

### Explaining array formula in cell E3

#### Step 1 - Identify records not displayed yet

The COUNTIFS function allows you to count cells based on multiple conditions, this makes it ideal for identifying unique distinct records, one condition corresponds to one value in the record.

If you have three values in one record then the COUNTIFS function contains three conditions or six arguments. Each condition has two arguments, the first argument in each pair is a growing cell reference meaning it expands when you copy the cell and paste to cells below.

COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0

becomes

{0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0}=0

and returns

{TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}.

This makes sense since no values have been displayed yet by the formula in cells above cell E3.

#### Step 2 - Calculate record frequency

The COUNTIFS function also lets you count identical records, by using the IF function we can convert the boolean values to the corresponding count if TRUE and blank "" if FALSE.

IF(COUNTIFS($E$2:E2, $A$2:$A$29, $F$2:F2, $B$2:$B$29, $G$2:G2, $C$2:$C$29)=0, COUNTIFS($A$2:$A$29, $A$2:$A$29, $B$2:$B$29, $B$2:$B$29, $C$2:$C$29, $C$2:$C$29), "")

becomes

IF({TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}, COUNTIFS($A$2:$A$29, $A$2:$A$29, $B$2:$B$29, $B$2:$B$29, $C$2:$C$29, $C$2:$C$29), "")

becomes

IF({TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}, {2; 1; 3; 5; 2; 4; 6; 6; 4; 5; 7; 7; 7; 6; 7; 5; 4; 7; 7; 6; 4; 7; 3; 6; 5; 6; 3; 5}, "")

and returns

{2; 1; 3; 5; 2; 4; 6; 6; 4; 5; 7; 7; 7; 6; 7; 5; 4; 7; 7; 6; 4; 7; 3; 6; 5; 6; 3; 5}.

The first value in the array above corresponds to the first record (row) in cell range $A$2:$C$29, thus 2 tells us that there is an identical record somewhere in cell range $A$2:$C$29. If we examine the list above you can see that the first record (row 2) is identical to the record in row 6.

Row 6 is the fifth value in the array above, that value must also be 2 if the formula works as intended. Yes, the fifth value is also 2.

#### Step 3 - Extract largest number from array

The LARGE function lets you extract the k-th largest value in a cell range or array, in this case, we are looking for the largest value and k is therefore 1.

LARGE(IF(COUNTIFS($E$2:E2, $A$2:$A$29, $F$2:F2, $B$2:$B$29, $G$2:G2, $C$2:$C$29)=0, COUNTIFS($A$2:$A$29, $A$2:$A$29, $B$2:$B$29, $B$2:$B$29, $C$2:$C$29, $C$2:$C$29), ""), 1)

becomes

LARGE({2; 1; 3; 5; 2; 4; 6; 6; 4; 5; 7; 7; 7; 6; 7; 5; 4; 7; 7; 6; 4; 7; 3; 6; 5; 6; 3; 5},1)

and returns 7.

#### Step 4 - Find position of largest value

The MATCH function returns the relative position of a value in an array or cell range. The array we match against is the frequency numbers multiplied with an array with boolean values that indicates if a record has already been shown in cells above the current cell.

MATCH(LARGE(IF(COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0,COUNTIFS($A$2:$A$29,$A$2:$A$29,$B$2:$B$29,$B$2:$B$29,$C$2:$C$29,$C$2:$C$29),""),1),COUNTIFS($A$2:$A$29,$A$2:$A$29,$B$2:$B$29,$B$2:$B$29,$C$2:$C$29,$C$2:$C$29)*(COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0),0)

becomes

MATCH(7,COUNTIFS($A$2:$A$29,$A$2:$A$29,$B$2:$B$29,$B$2:$B$29,$C$2:$C$29,$C$2:$C$29)*(COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0),0)

becomes

MATCH(7,{2; 1; 3; 5; 2; 4; 6; 6; 4; 5; 7; 7; 7; 6; 7; 5; 4; 7; 7; 6; 4; 7; 3; 6; 5; 6; 3; 5}*(COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0),0)

becomes

MATCH(7,{2; 1; 3; 5; 2; 4; 6; 6; 4; 5; 7; 7; 7; 6; 7; 5; 4; 7; 7; 6; 4; 7; 3; 6; 5; 6; 3; 5}*{TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE},0)

becomes

MATCH(7,{2; 1; 3; 5; 2; 4; 6; 6; 4; 5; 7; 7; 7; 6; 7; 5; 4; 7; 7; 6; 4; 7; 3; 6; 5; 6; 3; 5},0)

and returns 11. Number 7 is found int the 11-th position in the array.

#### Step 5 - Return value based on position

INDEX($A$2:$C$29,MATCH(LARGE(IF(COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0,COUNTIFS($A$2:$A$29,$A$2:$A$29,$B$2:$B$29,$B$2:$B$29,$C$2:$C$29,$C$2:$C$29),""),1),COUNTIFS($A$2:$A$29,$A$2:$A$29,$B$2:$B$29,$B$2:$B$29,$C$2:$C$29,$C$2:$C$29)*(COUNTIFS($E$2:E2,$A$2:$A$29,$F$2:F2,$B$2:$B$29,$G$2:G2,$C$2:$C$29)=0),0),COLUMN(A1))

becomes

INDEX($A$2:$C$29,11,COLUMN(A1))

becomes

INDEX($A$2:$C$29, 11, 1)

and returns "Maura Albers" in cell E3.

Remove common records between two data sets

This article demonstrates how to filter records occurring in only one out of two Excel defined tables. It also shows [โฆ]

Filter shared records from two tables

I will in this blog post demonstrate a formula that extracts common records (shared records) from two data sets in [โฆ]

Compare tables: Highlight records not in both tables

The image above demonstrates a conditional formatting formula that highlights records that only exist in one table. There are two [โฆ]

Compare two lists of data: Highlight common records

In this blog post I will demonstrate a conditional formatting formula that will highlight common records in two lists. The [โฆ]

Count unique distinct records (rows) in a Pivot Table

Excel 2013 allows you to count unique distinct values in a pivot table, this article explains how to use a [โฆ]

Count unique distinct records with a date and column criteria

davidlim asks: re: Count records between two dates and a criterion based on the example, i was looking for 1 [โฆ]

Filter unique distinct records with a condition

Sean asks: If Tea and Coffee has Americano,it will only return Americano once and not twice. I am looking for a [โฆ]

Filter unique distinct records

Table of contents Filter unique distinct row records Filter unique distinct row records but not blanks Filter unique distinct row [โฆ]

### 3 Responses to โUnique distinct records sorted based on count or frequencyโ

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

Thi site helped me crate a list of unique users from a data extract however I want to go one more step and next o the unique user add in the location they are at. Location is column A, user is column B and unique user is in column I, in column J I just want to have their location - can you direct or guide me to the tip to clip? Thank you!!

William J. Ryan,

Formula in J2:

Great formula! However, my list contains blank values. How do I account for this? With the above formula, the last value is repeated.