Excel: How to Count Unique Values Based on Multiple Criteria


You can use the following basic formula in Excel to count unique values based on multiple criteria:

=SUM(--(LEN(UNIQUE(FILTER(A:A,(Criteria1)*(Criteria2)*(Criteria3),"")))>0))

This particular formula counts the number of unique values in column A based on three criteria being met.

The following example shows how to use this formula in practice.

Example: Count Unique Values Based on Multiple Criteria in Excel

Suppose we have the following dataset in Excel that shows the conference and points scored for various basketball players:

Now suppose we’d like to count the number of unique player names who meet the following criteria:

  • The player is in the West conference.
  • The player has greater than 20 points.

We can use the following formula to count the number of unique player names who meet this criteria:

=SUM(--(LEN(UNIQUE(FILTER(A2:A14,(B2:B14="West")*(C2:C14>20),"")))>0))

We can type this formula into cell E2 of our spreadsheet:

From the output we can see there are 3 unique player names that are in the West conference and have more than 20 points.

We can verify this is correct by manually identifying each player who meets both criteria:

Out of the four players who meet both criteria, there are three unique player names:

  • Greg
  • Sean
  • Mike

Note that in this example we performed a count unique using two criteria, but we can use similar syntax to use as many criteria as we’d like.

Additional Resources

The following tutorials explain how to perform other common tasks in Excel:

Excel: How to Count If Cells Contain Text
Excel: How to Count Cells Not Equal to Value
Excel: How to Use COUNTIF with OR

4 Replies to “Excel: How to Count Unique Values Based on Multiple Criteria”

  1. What if you wanted to count how many different conferences each person played at and scored >1. So for Bob that would be 2 and for Greg it would be 1 etc

  2. Hi, I have an issue with my situation now, i would like to do the the same exact formula but the count unique comes from different worksheet, is there a chance that the formula can be extended to also count from different worksheet? I know i can settle this issue by combining both worksheet under one worksheet but it will be more additional manual things to do and would like to reduce this. Thank you in advance!

    1. Hi Leo…

      I’d be happy to help you sum the points scored from the players found in the previous example of counting unique values based on multiple criteria in Excel.

      —

      ### **Objective**

      – **Goal:** Sum the total points scored by **unique** players who meet specific criteria.

      ### **Assumptions**

      Based on the previous example, let’s assume you have a dataset structured like this:

      | **A** | **B** | **C** | **D** |
      |———–|———|————|———–|
      | Player | Team | Position | Points |
      | Player1 | TeamA | Forward | 10 |
      | Player2 | TeamB | Guard | 15 |
      | Player1 | TeamA | Forward | 12 |
      | Player3 | TeamA | Guard | 8 |
      | Player4 | TeamB | Forward | 20 |
      | Player2 | TeamB | Guard | 14 |
      | Player5 | TeamA | Forward | 11 |

      – **Columns:**
      – **A:** Player names (may have duplicates).
      – **B:** Team names.
      – **C:** Player positions.
      – **D:** Points scored.

      – **Criteria:**
      – **Team:** “TeamA”
      – **Position:** “Forward”

      —

      ### **Problem Explanation**

      – **Task:** Sum the total points scored by **unique** players who are **Forwards** in **TeamA**.
      – **Challenge:** Players may appear multiple times in the dataset. We need to avoid double-counting points from duplicate entries.

      —

      ### **Solution Methods**

      #### **Method 1: Using Advanced Functions (Excel 365 and Excel 2021)**

      **Step 1: Extract Unique Players Meeting Criteria**

      – **Formula:**

      In cell **F2**, enter:

      “`excel
      =UNIQUE(FILTER(A2:A8, (B2:B8=”TeamA”)*(C2:C8=”Forward”)))
      “`

      – **Explanation:**
      – `FILTER` extracts players where Team is “TeamA” and Position is “Forward”.
      – `UNIQUE` removes duplicates, giving a list of unique players who meet the criteria.

      **Step 2: Sum Points for Each Unique Player**

      – **Formula:**

      In cell **G2**, enter:

      “`excel
      =SUM(SUMIFS(D2:D8, A2:A8, F2#))
      “`

      – **Explanation:**
      – `SUMIFS` calculates the total points for each player in the unique list (`F2#` refers to the dynamic array from F2).
      – The outer `SUM` adds up the points of all unique players.

      **Result:**

      – The total points scored by unique Forwards in TeamA will be displayed in cell **G2**.

      —

      #### **Method 2: Using Pivot Table**

      **Step 1: Create a Pivot Table**

      1. Select your data range (**A1:D8**).
      2. Go to **Insert** > **PivotTable**.
      3. Choose to place the PivotTable on a new worksheet or existing one.

      **Step 2: Set Up the Pivot Table**

      – **Fields Placement:**
      – **Filters:** Add `Team` and `Position`.
      – **Rows:** Add `Player`.
      – **Values:** Add `Points` (ensure it’s set to **Sum**).

      **Step 3: Apply Filters**

      – In the PivotTable, set:
      – **Team** filter to **”TeamA”**.
      – **Position** filter to **”Forward”**.

      **Step 4: View the Result**

      – The PivotTable will display each unique player and the sum of their points.
      – The **Grand Total** at the bottom is the sum you’re looking for.

      —

      #### **Method 3: Using Helper Columns (Compatible with Older Excel Versions)**

      **Step 1: Identify Rows Meeting Criteria**

      – In cell **E2**, enter:

      “`excel
      =IF(AND(B2=”TeamA”, C2=”Forward”), A2, “”)
      “`

      – Copy the formula down to **E8**.

      – **Explanation:** Lists player names who meet the criteria; leaves others blank.

      **Step 2: Extract Unique Players**

      – In cell **F2**, enter:

      “`excel
      =IF(E2=””,””,IF(COUNTIF($E$2:E2,E2)=1,E2,””))
      “`

      – Copy down to **F8**.

      – **Explanation:** Lists each unique player only once.

      **Step 3: Sum Points for Each Unique Player**

      – In cell **G2**, enter:

      “`excel
      =IF(F2=””, “”, SUMIF(A$2:A$8, F2, D$2:D$8))
      “`

      – Copy down to **G8**.

      – **Explanation:** Calculates the total points for each unique player.

      **Step 4: Calculate Total Points**

      – In cell **H2**, enter:

      “`excel
      =SUM(G2:G8)
      “`

      – **Result:** Cell **H2** displays the total points scored by unique players meeting the criteria.

      —

      ### **Example Using Method 1**

      **Step 1: Extract Unique Players**

      – **Formula in F2:**

      “`excel
      =UNIQUE(FILTER(A2:A8, (B2:B8=”TeamA”)*(C2:C8=”Forward”)))
      “`

      – **Unique Players List:**

      | **F** |
      |————-|
      | Player1 |
      | Player5 |

      **Step 2: Sum Points for Unique Players**

      – **Formula in G2:**

      “`excel
      =SUM(SUMIFS(D2:D8, A2:A8, F2#))
      “`

      – **Calculation:**

      – **Player1’s Points:** 10 + 12 = 22
      – **Player5’s Points:** 11
      – **Total Sum:** 22 + 11 = **33**

      – **Result:** Cell **G2** displays **33**.

      —

      ### **Explanation**

      – **Why We Sum Unique Players’ Points:**
      – We need to ensure that each player’s points are summed correctly, even if they have multiple entries.
      – By extracting unique players, we avoid counting any player more than once in our final sum.

      – **Use of Dynamic Arrays (F2#):**
      – In Excel 365 and Excel 2021, `F2#` refers to the entire array of unique players starting from cell F2.

      —

      ### **Final Notes**

      – **Ensure Data Accuracy:**
      – Verify that your data ranges in the formulas match your actual data.
      – Adjust cell references if your dataset is larger or located in different cells.

      – **Version Compatibility:**
      – **Method 1** requires Excel 365 or Excel 2021 due to the use of dynamic array functions (`UNIQUE`, `FILTER`).
      – **Method 3** is suitable for older versions of Excel.

      – **Alternative Criteria:**
      – You can modify the criteria in the formulas to match different teams, positions, or other conditions.

      —

      ### **Feel Free to Ask**

      If you have any questions or need further assistance with any of these steps, please let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *