Count and Filter Most Frequent Strings in Google Sheets

Published on

Want to find out who appears most often in your data—like your top buyers, most frequent participants, or repeated responses? In Google Sheets, you can count how often each value appears in a list and easily filter the most frequent ones.

Whether you’re analyzing customer names, survey responses, or event attendance, this guide will show you a simple way to count and filter the most frequent strings in Google Sheets using built-in formulas—no manual work required.

Sample Data

EventParticipant
Marketing SummitSavannah
Dev ConferenceVincent
Marketing SummitSavannah
Sales WorkshopSandra
Dev ConferenceSavannah
Sales WorkshopDavid
Dev ConferenceSandra
Marketing SummitVincent
Sales WorkshopSavannah
Dev ConferenceSavannah

Assume you have event data like this, with event names in column A and participant names in column B.

To find the top 3 participants who appear most frequently in the data, you can use the formula below.

Formula to Count and Filter Most Frequent Strings in Google Sheets

=SORTN(
   HSTACK(
      TOCOL(UNIQUE(range), 3), 
      COUNTIF(range, TOCOL(UNIQUE(range), 3))
   ), n, 0, 2, FALSE
)
  • Replace 'range' with the range you want to analyze (e.g., B2:B to count participants).
  • 'n' determines the number of top values to return (e.g., 3 for the top 3).

Example

In the above example, to count and filter the most frequent 3 participant names, use the following formula:

=SORTN(
   HSTACK(
      TOCOL(UNIQUE(B2:B), 3), 
      COUNTIF(B2:B, TOCOL(UNIQUE(B2:B), 3))
   ), 3, 0, 2, FALSE
)

Result:

Example of counting and filtering the most frequent strings in Google Sheets

Note: If you want to filter the top N most frequent strings plus any additional strings tied at the Nth position, replace the display_ties_mode value 0 in the SORTN function with 1.

For example, SORTN(…, 3, 1, 2, FALSE) will include all values that share the same count as the 3rd most frequent string.

How the Formula Filters Most Frequent Strings

The formula works in two simple steps:

  1. Get unique values and their counts:
HSTACK(
   TOCOL(UNIQUE(B2:B), 3), 
   COUNTIF(B2:B, TOCOL(UNIQUE(B2:B), 3))
)
  • UNIQUE(B2:B) extracts distinct strings from column B.
  • TOCOL(..., 3) ensures the unique values are arranged vertically, skipping any empty cells.
  • COUNTIF(B2:B, ...) counts how often each unique value appears.
  • HSTACK(...) combines the values and their counts into a two-column array.
  1. Sort by count and return the top N results:
SORT(..., 3, 0, 2, FALSE)
  • SORTN selects the top 3 rows.
  • The 2 refers to the second column (count), which is used for sorting.
  • The FALSE indicates descending order, showing the most frequent values first.

Additional Tip: Get Associated Values for the Most Frequent Strings

What if you want to filter the most frequent values in one column and extract associated values from another?

Get associated values for the most frequent strings in Google Sheets

For example, the most frequent three participants from the sample data are:

  • Savannah
  • Vincent
  • Sandra

To get the associated events for each of these names, use this two-step setup:

Step 1: Get Top Participants (in D2)

=CHOOSECOLS(
   SORTN(
      HSTACK(
         TOCOL(UNIQUE(B2:B), 3), 
         COUNTIF(B2:B, TOCOL(UNIQUE(B2:B), 3))
      ), 3, 0, 2, FALSE
   ), 1
)

Used CHOOSECOLS to return only the first column (the values), excluding the count column.

Step 2: Get Their Associated Events (in E2)

=MAP(
   D2:D, 
   LAMBDA(
      row, 
      TEXTJOIN(", ", TRUE, UNIQUE(FILTER(A2:A, B2:B=row)))
   )
)

This will return a comma-separated list of events attended by each top participant.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.