Calculating Percentile for Each Group in Google Sheets

Currently, Google Sheets does not have a dedicated function to calculate the percentile for each group directly. However, we can achieve this using a combination of the PERCENTILE function with FILTER or IF.

Why Calculate Percentiles for Each Group?

Consider a table containing students’ marks across two different grades (or classes).

If you want to calculate the 75th percentile of all the marks, you can simply use the PERCENTILE function:

=PERCENTILE(all_marks, 0.75)

However, if you need to calculate the percentile for each grade separately, the PERCENTILE function alone won’t work. Instead, we must combine it with FILTER or IF to calculate the percentile for each group in Google Sheets.

Understanding the PERCENTILE Function

Before diving into an example with marks and grades, let’s briefly explain the PERCENTILE function and how it differs from other statistical functions like AVERAGE, MIN, MAX, MEDIAN, and RANK.

  • PERCENTILE returns the value below which a given percentage of data points fall.
  • The 50th percentile is equivalent to the median of a dataset.
  • For example, in the dataset {5, 6}, the median is 5.5, which is also the 50th percentile.

Both PERCENTILE and MEDIAN interpolate values to determine the percentile.

How to Calculate the k-th Percentile for Each Group in Google Sheets

Understanding k-th Percentile

  • The k-th percentile represents a specific value in the dataset, where k is between 0 and 1 (or 0% to 100%).
  • For example, the 60th percentile can be written as 0.6 or 60%.

Example: Calculating the 60th Percentile for a Dataset

Sample Data:

Student NameGrade (Class)Marks
SaulGrade 160
AllisonGrade 166
LydiaGrade 179
PeterGrade 180
SherryGrade 179
LyleGrade 275
AdamGrade 278
JordanGrade 290
CarlosGrade 299
TommieGrade 268
LolaGrade 282
CherylGrade 399
RogerGrade 399
AngelinaGrade 397
JudithGrade 358
VickyGrade 355
FrancisGrade 390

To calculate the 60th percentile of all students’ marks, use:

=PERCENTILE(C2:C18, 0.6)

Result: 81.20

This means 60% of students scored below 81.20 marks.

Calculating Percentile for Each Group in Google Sheets

Step 1: Get Unique Groups (Grades)

First, list unique grades using the UNIQUE function. In cell E3, enter:

=UNIQUE(B2:B)
Percentile Calculation for Each Unique Group in Google Sheets

Step 2: Calculate the 60th Percentile for Each Group

Now, we calculate the percentile for each group using FILTER and PERCENTILE.

In cell F3, enter the following formula and drag it down:

=PERCENTILE(FILTER($C$2:$C, $B$2:$B=E3), 0.6)

How It Works:

  • FILTER($C$2:$C, $B$2:$B=E3): Extracts only the marks for the current grade.
  • PERCENTILE(..., 0.6): Calculates the 60th percentile for that group.

Alternative Method: Using PERCENTILE with IF

Instead of FILTER, you can also use IF inside an ArrayFormula:

=ArrayFormula(PERCENTILE(IF($B$2:$B=E3, $C$2:$C), 0.6))
  • IF($B$2:$B=E3, $C$2:$C): Returns marks for the matching grade, otherwise FALSE.
  • PERCENTILE(..., 0.6): Computes the 60th percentile.

Both formulas will return the percentile marks for Grade 1, Grade 2, and Grade 3.

Creating a Percentile Column for All Rows

If you want to calculate the percentile for each group in a new column without listing unique grades separately, modify the FILTER function criterion to use column B directly.

In cell D2, enter the following formula and drag it down to apply it to all rows:

=PERCENTILE(FILTER($C$2:$C, $B$2:$B=B2), 0.6)
Row-wise Percentile Calculation for Each Group in Google Sheets

How This Works:

  • The formula dynamically calculates the percentile for each student’s grade without needing a separate list of unique grades.

Note: As you can see, my sample data is sorted by category (grade), but sorting is not required for this calculation.

Frequently Asked Questions (FAQ)

1. What is the difference between PERCENTILE and PERCENTRANK in Google Sheets?

  • The PERCENTILE function returns the actual value at a given percentile.
  • The PERCENTRANK function returns the relative rank (as a percentage) of a value within a dataset.
  • Example:
=PERCENTILE(A2:A10, 0.75)  // Returns the 75th percentile value  
=PERCENTRANK(A2:A10, B2)   // Returns the rank of B2 as a percentile  

2. Can I calculate percentiles without using the FILTER function?

Yes, you can use the IF function inside an ArrayFormula instead of FILTER:

=ArrayFormula(PERCENTILE(IF($B$2:$B=B2, $C$2:$C), 0.6))

However, FILTER is usually more efficient and readable.

3. Can I calculate the percentile for each group dynamically?

Yes! Use the MAP function (Lambda) to get the percentile for each group on-the-fly:

=IFERROR(MAP(B2:B, LAMBDA(row, PERCENTILE(FILTER($C$2:$C, $B$2:$B=row), 0.6))))

Simply enter this formula in cell D2. It automatically calculates the 60th percentile for each group and updates dynamically when new data is added.

Conclusion

By combining PERCENTILE with FILTER or IF, you can dynamically calculate the percentile for each group in Google Sheets. Whether you use a separate summary table or calculate it inline within the dataset, these methods help in statistical analysis, grading, and performance evaluation.

Related Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Filter Top N per Category in Excel (Using FILTER & COUNTIFS)

You can use a combination of FILTER and COUNTIFS to filter the top N...

Rank per Group in Excel

You have two groups of 20 students each. How do you determine the rank...

Real-Time Excel Filtering Using Combo Box & FILTER Function

In this tutorial, you’ll learn how to set up real-time Excel filtering using a...

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

More like this

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

How to Extract Top N from Aggregated Query Results in Google Sheets

To summarize data in Google Sheets, you can use the QUERY function. However, if...

How to Use RANK IF in Google Sheets (Conditional Ranking)

You can use the RANK function to rank values in an entire dataset. But...

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.