HomeGoogle DocsSpreadsheetQuartile IF in Google Sheets

Quartile IF in Google Sheets

Published on

To calculate quartiles based on conditions, referred to as “Quartile IF,” we will use a combination of formulas in Google Sheets.

Sometimes, you may want to calculate quartiles based on specific conditions, such as the quartile of test scores for students who scored above a certain threshold, or values that fall within specific date ranges, months, or years.

The QUARTILE function does not accept criteria, and there is no QUARTILEIF function available in Google Sheets. Therefore, we resort to workarounds that involve the FILTER function.

We will filter the values based on conditions using FILTER, and for that, we can also use QUERY. Another option is the IF function. We will explore all these varieties in this tutorial.

Quartile IF Analysis in Google Sheets

In the following example, I have student names in column A and their test scores in column B. Let’s find quartiles 0 to 4 of test scores above 70. Please note that we will use the range B2:B as B1 contains the field label.

Sample data table for demonstrating Quartile IF analysis with numeric criterion

In Quartile IF, the logic is to extract the values that fall within the threshold limit, where in this case, the test scores are greater than or equal to 70.

The following formula can be used to extract the values that fall within the threshold limit:

=FILTER(B2:B, B2:B>=70)

In the above FILTER formula, the range to filter is B2:B, and the condition is B2:B>=70. You just need to wrap it with the QUARTILE function and specify the quartile number to get the quartile:

=QUARTILE(FILTER(B2:B, B2:B>=70), 3)

The above formula will return the third quartile. If you want to get quartiles 0, 1, 2, 3, and 4 in one go, specify the quartile numbers as an array and enter the formula as an array formula:

=ArrayFormula(QUARTILE(FILTER(B2:B, B2:B>=70), HSTACK(0, 1, 2, 3, 4)))

Result: {75, 81, 86.5, 90.5, 95}

Min Value
(0% mark)
Second Quartile
(25% mark)
Median
(50% mark)
Third Quartile
(75% mark)
Max Value
(100% mark)
758186.590.595

In this formula, we have used the HSTACK function to create a one-dimensional horizontal array of quartile numbers. If you want the result vertically, replace HSTACK with VSTACK.

FILTER Replacement:

QUERY: QUERY(B2:B, "SELECT B WHERE B>=70", 0)

IF: =ArrayFormula(IF(B2:B>=70, B2:B))

Quartile IFs Analysis in Google Sheets

In the above examples, we have specified one condition, i.e., test score >=70. Here, let’s see how to calculate Quartile IFs with multiple conditions.

Here, we have dates in column A and numeric values in column B.

Sample data table for demonstrating Quartile IFs analysis with date criterion

How do we calculate the second quartile in a specific year, for example, 2024?

The following FILTER formula filters column B if the year in column A falls in 2024:

=FILTER(B2:B, YEAR(A2:A)=2024)

In this FILTER formula, the range to filter is B2:B, and the criterion is YEAR(A2:A)=2024. The YEAR function extracts the year from the date.

Wrap it with the QUARTILE function as below:

=QUARTILE(FILTER(B2:B, YEAR(A2:A)=2024), 2)

This is still an example of Quartile IF as it holds one criterion. What about multiple conditions Quartile IFs?

For example, we need to filter the dates that fall in the years 2023 and 2024 and find the quartile. We can use either of the below FILTER formulas for that:

=FILTER(B2:B, (YEAR(A2:A)=2023)+(YEAR(A2:A)=2024))
=FILTER(B2:B, ISBETWEEN(YEAR(A2:A), 2023, 2024))

Wrap it with QUARTILE and specify the quartile number.

Additional Tips

What about Quartile IFs with a date range?

The following formula answers this:

=FILTER(B2:B, A2:A>=DATE(2024, 1, 1), A2:A<=DATE(2024, 2, 29))

It filters the data that falls between January 1, 2024, and February 29, 2024.

Notes:

  • In the above formula, the date is specified in the DATE function syntax DATE(year, month, day).
  • In date range formulas, whenever you want to specify month-end dates such as DATE(2024, 2, 29) in the above example, I suggest using EOMONTH(DATE(2024, 2, 1), 0) which converts the beginning of the month date to the end of the month date and ensures we are using the correct month-end date.

Conclusion

To master Quartile IF, it’s essential to become proficient with either the FILTER function or the IF function. This mastery enables you to filter values based on conditions, which can then be utilized within the QUARTILE function.

For more advanced filtering capabilities, consider using QUERY. All these functions are available for learning within my function guide.

You may also be interested in: How to Calculate the Interquartile Range (IQR) in Google Sheets.

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.

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

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.