How to Unique Values By Count in Excel

Learn multiple Excel methods to extract unique values by count with step-by-step examples, business scenarios, and best practices.

excelformulaspreadsheettutorial
12 min read • Last updated: 7/2/2025

How to Unique Values By Count in Excel

Why This Task Matters in Excel

Imagine you receive a customer-order export every morning: thousands of rows containing customer IDs, product names, regions, and order dates. Management asks, “Which products sold the most yesterday? Give me the list ranked from highest to lowest sales.”
Another day the marketing department wants to know which email domains appear most frequently in your subscriber list, and HR wants a headcount of employees by department, sorted so that the largest departments appear first.

All those requests translate to the same technical need: pull a list of unique items and organize (or filter) them by how many times they appear. The task crops up everywhere:

  • Sales: Rank products, sales reps, or store locations by sales volume.
  • Operations: Identify top-returning SKUs by frequency to spot quality issues.
  • Finance: Summarize expense categories by number of transactions for audit sampling.
  • Marketing: Surface the most common keywords in survey responses.
  • IT & Security: List the most mis-typed login attempts by username count.

Excel excels (pun intended) at quick ad-hoc analysis—no database queries needed, no code deployment. In minutes, you can answer “Which X appears most?” and back it with exact counts.

Failing to master this skill carries heavy costs:

  • Manual deduping and counting takes hours and is error-prone.
  • Decision makers receive stale or incorrect rankings.
  • Inability to identify outliers or high-frequency items hides potential fraud or process issues.

Lastly, extracting unique values by count is gateway knowledge. It links naturally to other analytical workflows: dashboards, dynamic charts, KPI scorecards, or advanced modeling in Power Query and Power Pivot. Mastering it tightens your control over data insights and speeds up day-to-day reporting.

Best Excel Approach

The optimal modern solution combines three dynamic array functions: UNIQUE, COUNTIF, and SORTBY. Together they create a spill range listing each distinct value exactly once, alongside or sorted by its occurrence count—no helper columns if you prefer, yet fully dynamic when data changes.

Why this trio?

  • UNIQUE instantly strips duplicates.
  • COUNTIF counts each unique value against the source list.
  • SORTBY rearranges the results by those counts, either descending or ascending.

Prerequisites: Excel 365 or Excel 2021 with dynamic arrays enabled. If you run an older version, jump ahead to the Alternative Methods section for PivotTable and legacy formula options.

Core logic:

  1. Pull distinct items.
  2. Compute counts for each distinct item.
  3. Sort the distinct list using the counts as the sort key.

Syntax pattern (single formula, no helper column):

=SORTBY(
    UNIQUE([SourceRange]),
    COUNTIF([SourceRange], UNIQUE([SourceRange])),
    -1
)
  • [SourceRange] is the column or vector containing repeated values.
  • COUNTIF creates a parallel array of counts.
  • -1 tells SORTBY to sort descending (largest count first). Use 1 for ascending.

If you do want to expose the counts in a neighboring column, use a two-spill formula:

=LET(
  u, UNIQUE([SourceRange]),
  c, COUNTIF([SourceRange], u),
  HSTACK(u, c)
)

Then optionally wrap with SORT or SORTBY.

Parameters and Inputs

  • SourceRange (required): The list containing duplicates, ideally a single column. Dynamic ranges like structured table columns ([Table1[Product]]) or spilled arrays are fully supported.
  • Delimiter/IgnoreEmpty (UNIQUE optional flags): Most users leave defaults, but IgnoreEmpty ensures blanks are treated correctly.
  • SortOrder in SORTBY: -1 for descending, 1 for ascending.
  • Data type consistency: COUNTIF treats numbers and text accurately, but beware of stray spaces or mismatched capitalization if you later use case-sensitive functions.
  • Data preparation: Remove leading/trailing spaces using TRIM or Power Query to ensure “Product A” and “Product A ” do not appear separately.
  • Edge cases:
    – Blank cells: Decide whether to keep or drop them. UNIQUE skips blanks if you set ignore_empty to TRUE.
    – Error values in source: Wrap formula with IFERROR or FILTER to exclude them.
    – Mixed data types within one column can throw off COUNTIF; standardize before analysis.

Step-by-Step Examples

Example 1: Basic Scenario – Count Cities in a Small List

Assume a short list of cities in [A2:A15]:

New York
Chicago
New York
Dallas
Seattle
Chicago
Chicago
Boston
New York
Miami
Seattle

Step 1 – Put the formula in [C2]:

=SORTBY(
  UNIQUE(A2:A15),
  COUNTIF(A2:A15, UNIQUE(A2:A15)),
  -1
)

Explanation:

  1. UNIQUE(A2:A15) returns a spill range like
    New York | Chicago | Dallas | Seattle | Boston | Miami
  2. COUNTIF counts each item within the source list, yielding
    3 | 3 | 1 | 2 | 1 | 1
  3. SORTBY pairs each city with its count and sorts by the count descending.

Expected result (spilled vertically starting in [C2]):

New York
Chicago
Seattle
Dallas
Boston
Miami

The companion counts can be displayed in [D2] by altering the formula:

=LET(
  u, UNIQUE(A2:A15),
  c, COUNTIF(A2:A15, u),
  SORTBY( HSTACK(u, c), c, -1)
)

Why it works: COUNTIF’s second argument accepts the entire spilled array u, producing a parallel array of counts in the same order. SORTBY then moves both columns in lock-step.

Variations: Ascending order? Replace -1 with 1. Need only top three? Wrap final spill with TAKE(…,3).

Troubleshooting tips:

  • If the spill shows a #SPILL! error, ensure nothing blocks the output cells.
  • If counts appear misaligned, verify that u remains unchanged between COUNTIF and SORTBY—typos in the variable names break LET definitions.

Example 2: Real-World Application – Top-Selling Products Report

Context: In [TableSales], column Product lists 5,000 transaction lines for the month. Management wants the top ten products by units sold, plus a chart updating automatically.

Data range: [TableSales[Product]]

Step-by-Step:

  1. In a summary sheet, cell [B5], enter:
=LET(
    src, TableSales[Product],
    u, UNIQUE(src),
    c, COUNTIF(src, u),
    sorted, SORTBY(HSTACK(u, c), c, -1),
    TAKE(sorted, 10)
)

This formula:

  • Defines src once for efficiency, avoiding multiple table lookups.
  • Builds u (unique products) and c (their counts).
  • Stacks them side by side.
  • Sorts descending by counts.
  • Uses TAKE to return only the first 10 rows.
  1. Format column widths and add a header row: “Product” and “Units Sold”. Because the spill lands directly below, headers remain fixed when the spill size changes.

  2. Create a dynamic bar chart:

  • Select any cell within the spill range.
  • Insert → Charts → Bar.
  • Excel auto-expands the chart’s series to follow the dynamic array.

Business value: This workflow replaces manual PivotTable copies into PowerPoint each month. The summary sheet auto-updates when new transactions are appended to TableSales. Chart titles and data labels can reference the same spill for zero maintenance.

Integration with other features:

  • Conditional formatting bars in the counts column.
  • Data validation lists referencing the unique product list for report filters.
  • Power Automate or VBA can export the chart image for distribution.

Performance notes:

  • Even with 50,000 rows, UNIQUE + COUNTIF remains fast because Excel now calculates arrays natively.
  • LET prevents recalculating TableSales[Product] multiple times, shaving milliseconds off each calc cycle.

Example 3: Advanced Technique – Multi-Criteria Unique Counts with Spill-Safe Filters

Scenario: You need the most common combinations of “Region & Product” filtered to only the current quarter, sorted by sales count. The data table [SalesData] contains Date, Region, Product, Quantity.

Goal: Unique values = every concatenated Region-Product pair, counted only where Date falls in the current quarter. Then list top 15.

Steps:

  1. Define a helper column on the fly using LET. In cell [E4]:
=LET(
    dates, SalesData[Date],
    products, SalesData[Product],
    regions, SalesData[Region],
    periodFilter, FILTER(SEQUENCE(ROWS(dates)), (dates >= EDATE(TODAY(), -MOD(MONTH(TODAY())-1,3))) * (dates <= TODAY())),
    combined, regions & " | " & products,
    filteredCombined, INDEX(combined, periodFilter),
    u, UNIQUE(filteredCombined),
    c, COUNTIF(filteredCombined, u),
    SORTBY(HSTACK(u, c), c, -1)
)

Explanation of advanced points:

  • periodFilter builds a row index array only for dates inside the current quarter. Using SEQUENCE allows INDEX to pull non-contiguous rows.
  • combined concatenates Region & Product with a pipe separator.
  • filteredCombined uses INDEX to gather only rows matching the quarter filter.
  • UNIQUE and COUNTIF run on the filtered set, not the full table.
  • Finally, sorted results spill into columns E and F as “Region | Product” and “Qty”.

Performance optimization:

  • Intermediate arrays live only in memory, avoiding worksheet helper columns.
  • Using LET reuses arrays (dates, products, regions) without trips back to worksheet memory.

Error handling:

  • If no data exists for the quarter, FILTER returns a #CALC! error. Wrap the outer formula with IFERROR(…, \"No data\") to provide a friendly message.

Professional tips:

  • Swap COUNTIF with SUMIFS if you want total quantities instead of transaction counts.
  • Split the pipe into two columns later using TEXTAFTER/TEXTBEFORE if separate Region and Product columns are required for charts.

Tips and Best Practices

  1. Store source data in Excel Tables. They auto-expand and keep formulas referencing them dynamic, eliminating the need to resize ranges manually.
  2. Wrap complex formulas in LET to improve readability and performance. Name intermediate arrays like u, c, src for clarity.
  3. Present counts alongside unique values using HSTACK; avoid separate helper columns scattered across the sheet.
  4. Use TAKE, DROP, and CHOOSECOLS to create top-N or custom‐view reports without additional formulas.
  5. Combine dynamic arrays with conditional formatting (e.g., data bars on count column) to make hotspots pop visually.
  6. For very large datasets, push preliminary filtering into Power Query, then apply UNIQUE + COUNTIF on the reduced rows for maximum speed.

Common Mistakes to Avoid

  1. Forgetting to fix the second COUNTIF argument. If you type COUNTIF(src, UNIQUE(src)) but later insert rows above, src might shift while UNIQUE(src) remains anchored, causing misaligned counts. Use LET variables or absolute references to avoid drift.
  2. Accidentally blocking spill output. Any value in the spill range causes #SPILL!. Keep a buffer of blank rows/columns or place the formula in an empty section.
  3. Treating “Product A” and “product a” as identical when Excel sees them as different. Apply LOWER or UPPER first if case does not matter.
  4. Ignoring trailing spaces from imported systems; “Boston” ≠ “Boston “. Clean data with TRIM or CLEAN.
  5. Using volatile INDIRECT to build source ranges. INDIRECT forces full recalculation and breaks Table advantages. Prefer structured references or CHOOSECOLS.

Alternative Methods

While UNIQUE + COUNTIF + SORTBY is ideal in modern Excel, you have choices:

| Method | Excel Version | Dynamic | Pros | Cons | | (UNIQUE + COUNTIF + SORTBY) | 365/2021 | Yes | Single cell, auto-updates, minimal overhead | Requires newest versions | | PivotTable (Row Labels + Values) | 2007+ | Semi-dynamic | Drag-and-drop, totals by default, slicers | Needs refresh; limited formula control | | Power Query (Group By) | 2016+ (add-in earlier) | Refreshable | Handles millions of rows, merges + cleans | Learning curve, refresh step | | Legacy Array with FREQUENCY/MATCH | 2007-2019 | No | Works in older versions | C-array entry (Ctrl+Shift+Enter), brittle | | VBA Dictionary | 2000+ | Programmatic | Infinite flexibility, sorts counts | Requires macro-enabled workbook, security prompts |

When to choose:

  • PivotTable for quick ad-hoc summaries you need to slice by other fields.
  • Power Query for ETL pipelines or datasets beyond a few hundred thousand rows.
  • Legacy arrays if you cannot upgrade Office immediately.
  • VBA for fully customized or automated workflows inaccessible to formulas.

Performance: Power Query handles the largest volume, but inside-workbook dynamic arrays beat PivotTables for recalculation speed on datasets under 100k rows.

Migration: You can convert a PivotTable to formulas by using GETPIVOTDATA or moving the logic into UNIQUE + COUNTIF after upgrading Office.

FAQ

When should I use this approach?

Use it whenever you must rank or display distinct items based on how often they appear—top customers, most common error codes, or site visits per browser—especially if the source data updates frequently and you need outputs to refresh instantly.

Can this work across multiple sheets?

Yes. Wrap each sheet’s range in VSTACK or CHOOSECOLS, then feed the combined array into UNIQUE. Example:

=LET(
  src, VSTACK(Sheet1!A2:A500, Sheet2!A2:A500),
  SORTBY(UNIQUE(src), COUNTIF(src, UNIQUE(src)), -1)
)

What are the limitations?

Dynamic arrays require Office 365/2021. Counts are limited by COUNTIF’s 255-character criteria limit on text; long strings may need helper columns with IDs. Sorting ties are not further sub-sorted; add a second key in SORTBY if needed.

How do I handle errors?

Wrap formulas with IFERROR or FILTER to exclude error cells in the source, or cleanse data first. For expected blanks, set ignore_empty in UNIQUE to TRUE.

Does this work in older Excel versions?

Not natively. Use a PivotTable, Power Query, or the classic array trick: FREQUENCY with MATCH and a sorting helper column. See Alternative Methods.

What about performance with large datasets?

Dynamic arrays are efficient up to hundreds of thousands of rows. Above that, Power Query, Power Pivot, or a database might be faster. Using LET, avoiding volatile functions, and employing structured tables keep recalculations snappy.

Conclusion

Extracting unique values by count is a cornerstone Excel skill: it turns raw, noisy lists into ranked, actionable insights in seconds. With modern dynamic array functions, you can achieve it in a single formula that automatically expands and recalculates as data changes. Whether you are building dashboards, answering quick management questions, or auditing data quality, mastering this technique strengthens your analytical repertoire. Continue exploring by combining these arrays with charts, data validation, and Power Query, and you’ll unlock even deeper layers of data intelligence.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.