Calculation Issues

How to Calculate Median Payments by Sex and Quartile in Excel

John WilsonJohn Wilson Nov 11, 2026 868 views

Question details

The user needs to calculate median payment amounts for four different quartiles, categorized separately by sex.

How to Calculate Median Payments by Sex and Quartile in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
Analyzing employee payment data to find the median value within each quartile, broken down by male and female employees.
Observed behavior
Requires a complex formula to dynamically filter the data by sex, divide the payments into four quartiles, and calculate the median for each respective quartile.
Before you start

Ensure your dataset is formatted as an Excel Table (e.g., named 'tblData') with distinct columns for Sex and Payment. Microsoft 365 is highly recommended for the single-formula dynamic array solution.

Solution 1Recommended

Use a Dynamic Array Formula (Microsoft 365)

Utilize a combination of REDUCE, UNIQUE, FILTER, and MAKEARRAY functions to instantly generate a complete matrix of median values for all sexes and quartiles.

This approach leverages advanced dynamic array capabilities introduced in Microsoft 365 to calculate the medians across four quartiles for both male and female categories without needing multiple helper columns.

1
Prepare the Data Table

Ensure your dataset is converted into an Excel Table named 'tblData'. Verify that the column containing gender information is named 'Sex' and the column containing amounts is named 'Payment'.

2
Enter the Formula

Select a blank cell where you want the top-left of your results to appear. Type the following formula exactly: =DROP(REDUCE("",UNIQUE(tblData[Sex]),LAMBDA(a,v,LET(arr,FILTER(tblData[Payment],tblData[Sex]=v),m,MAKEARRAY(1,4,LAMBDA(r,c,LET(pq,QUARTILE.INC(arr,c-1),cq,QUARTILE.INC(arr,c),MEDIAN(FILTER(arr,IFS(c=1,arr<cq,c=4,arr>pq,TRUE,(arr>pq)*(arr<=cq))))))),VSTACK(a,m)))),1)

3
Execute the Formula

Press Enter. The formula will automatically spill the calculated median values into the adjacent cells, neatly categorized by sex in rows and quartiles in columns.

Use a Dynamic Array Formula (Microsoft 365)
Version Compatibility: This dynamic array formula only works in Microsoft 365 or Excel 2021. Older versions will return a #NAME? error and require helper columns or separate array formulas.
Advanced Data Analysis

Use WPS Spreadsheet for Advanced Array Formulas

WPS Spreadsheet fully supports advanced array formulas, including UNIQUE, FILTER, and REDUCE, allowing you to quickly calculate median values by category and quartile without needing an expensive subscription.

  1. 1. Open your data: Launch WPS Spreadsheet and open your existing Excel workbook containing the employee payment data.
  2. 2. Format as Table: Highlight your data, navigate to the Home tab, and select 'Format as Table'. Name the table 'tblData'.
  3. 3. Apply the Formula: Paste the dynamic array formula into a blank cell and press Enter. WPS Spreadsheet will automatically spill the calculated medians by sex and quartile.
Fully compatible with Microsoft Excel formulas (.xlsx)Supports modern dynamic array functions out of the boxFree to use with a lightweight, user-friendly interfaceBuilt-in advanced data analysis and charting tools
microsoft office alternative - wps office

Frequently Asked Questions

What is the difference between QUARTILE.INC and QUARTILE.EXC in Excel?

QUARTILE.INC includes the 0th and 4th quartiles (the absolute minimum and maximum values) in its calculation range, whereas QUARTILE.EXC excludes them. For most standard financial analyses and statistical mappings, QUARTILE.INC is generally preferred.

Why am I getting a #NAME? error when pasting the dynamic formula?

A #NAME? error typically means your version of Excel does not support newer functions like REDUCE, MAKEARRAY, or FILTER. You must upgrade to Microsoft 365, Excel 2021, or use WPS Spreadsheet which supports these modern dynamic array functions.

How can I adjust the formula if my columns are named differently?

In the provided formula, replace 'tblData[Sex]' and 'tblData[Payment]' with the actual Table Name and Column Headers used in your workbook. Alternatively, you can directly input the fixed cell ranges like '$B$2:$B$100' and '$C$2:$C$100' in place of the table references.