To calculate a percentile in Google Sheets based on a condition, use the PERCENTILE function inside an IF array formula: =PERCENTILE(IF(range=condition, data_range), percentile) and press Ctrl+Shift+Enter (or Cmd+Shift+Enter on Mac) to make it an array formula. For example, =PERCENTILE(IF(A2:A100="North", B2:B100), 0.9) returns the 90th percentile of sales for the “North” region.
Why PERCENTILE IF Isn’t a Built-in Function
Google Sheets has a PERCENTILE function and a separate IF function, but no combined “PERCENTILEIF” like it has SUMIF or AVERAGEIF. That means you have to combine them manually. The trick is to use IF to return only the values that meet your condition, and then feed that filtered array into PERCENTILE. Because IF normally returns a single value, you need to enter it as an array formula so it evaluates the entire range at once.
How to Write the PERCENTILE IF Formula
Assume your data has regions in column A (A2:A100) and sales figures in column B (B2:B100). To find the 90th percentile of sales for the “North” region:
- Click on an empty cell, e.g., D2.
- Type:
=PERCENTILE(IF(A2:A100="North", B2:B100), 0.9) - Press Ctrl+Shift+Enter (Windows) or Cmd+Shift+Enter (Mac). Google Sheets will automatically wrap the formula in curly braces
{ }to show it’s an array formula.
The result will be the value below which 90% of the North region’s sales fall. If you want the 25th percentile, replace 0.9 with 0.25.
Using PERCENTILE IF with Multiple Conditions
You can extend the formula to handle multiple criteria using the multiplication operator (*) inside the IF. For instance, to find the 75th percentile of sales for the “North” region in the “Q1” quarter (with quarter in column C):
=PERCENTILE(IF((A2:A100="North")*(C2:C100="Q1"), B2:B100), 0.75)
Press Ctrl+Shift+Enter. The multiplication works like an AND: each condition returns TRUE/FALSE, and multiplying them converts to 1/0, so the IF only includes rows where both are TRUE.
Common Errors and How to Fix Them
If you get a #VALUE! error, it usually means you forgot to press Ctrl+Shift+Enter. Without array entry, the IF only evaluates the first cell, and PERCENTILE can’t work with a single value. If you get a #N/A error, it means no rows match your condition—check for typos or extra spaces in your criteria. If your data contains text or blank cells in the value range, PERCENTILE will ignore them, but if the entire range is text, you’ll get #VALUE!.
Another issue: the IF condition must be exactly the same length as the value range. If you use A2:A100 but B2:B99, the formula will return an error. Always keep the row ranges identical.
Alternative: Using FILTER with PERCENTILE
If you prefer a non-array formula, you can use FILTER to extract the matching values first, then apply PERCENTILE to the filtered result. For example:
=PERCENTILE(FILTER(B2:B100, A2:A100="North"), 0.9)
This works without pressing Ctrl+Shift+Enter because FILTER is already an array function. It’s often easier to read and debug. The downside is that FILTER requires Google Sheets (it’s not available in Excel), but since you’re in Sheets, it’s a clean alternative. For multiple conditions, use FILTER(B2:B100, A2:A100="North", C2:C100="Q1").
PERCENTILE vs. PERCENTILE.INC vs. PERCENTILE.EXC
Google Sheets has three percentile functions: PERCENTILE (same as PERCENTILE.INC), PERCENTILE.INC, and PERCENTILE.EXC. The .INC version includes the 0th and 100th percentiles (the min and max), while .EXC excludes them. For most business and academic uses, PERCENTILE.INC is the default choice. If you want to replicate Excel’s PERCENTILE.EXC, you can use it in the same array formula: =PERCENTILE.EXC(IF(A2:A100="North", B2:B100), 0.9). Just be aware that PERCENTILE.EXC will return an error if your percentile is 0 or 1, or if your data has fewer than 2 values.
Frequently Asked Questions
Can I use PERCENTILE IF with text conditions like “contains”?
Yes, use wildcards with the IF condition. For example, to match any region starting with “N”, use =PERCENTILE(IF(REGEXMATCH(A2:A100, "^N"), B2:B100), 0.9). REGEXMATCH works in array formulas and lets you use regular expressions. Alternatively, you can use IF(LEFT(A2:A100,1)="N", ...) but that’s less flexible.
Why does my formula return the same value as the overall percentile?
That usually means your condition is matching all rows, or you forgot to enter it as an array formula. If you press Enter instead of Ctrl+Shift+Enter, the IF only checks the first cell, and if that cell matches, it returns the entire range—so the percentile is calculated on all data. Always use Ctrl+Shift+Enter.
Can I use PERCENTILE IF in Excel?
Yes, the same array formula works in Excel, but you must press Ctrl+Shift+Enter in older versions. In Excel 365, dynamic arrays handle it automatically without the special key combination. The syntax is identical: =PERCENTILE(IF(A2:A100="North", B2:B100), 0.9).
How do I find the 90th percentile excluding outliers?
You can add a condition to exclude values above a threshold. For example, to exclude sales over 1000: =PERCENTILE(IF((A2:A100="North")*(B2:B100<=1000), B2:B100), 0.9). This filters out the extreme values before calculating the percentile.
Is there a way to do PERCENTILE IF without array formulas?
Yes, use the FILTER function as shown above, or use a helper column. In a helper column, put =IF(A2="North", B2, "") and drag down, then use =PERCENTILE(C2:C100, 0.9). This is simpler for beginners but adds a column to your sheet.
Practical Example with Real Data
Suppose you have a list of 50 students with their test scores in column B and their class (“A” or “B”) in column A. To find the 90th percentile score for class A, you’d use:
=PERCENTILE(IF(A2:A51="A", B2:B51), 0.9)
If the scores are in B2:B51 and class labels in A2:A51, and you press Ctrl+Shift+Enter, the formula returns the score that is higher than 90% of class A’s scores. For instance, if class A has 30 scores and the 27th highest is 85, then the 90th percentile is 85.