How to Calculate Median Payments by Sex and Quartile in Excel
Question details
The user needs to calculate median payment amounts for four different quartiles, categorized separately by sex.

- 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.
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.
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.
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'.
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)
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 Helper Columns and Standard Array Formulas (Older Excel Versions)
If you are not using Microsoft 365, calculate the quartiles using helper cells and then find the median using standard array formulas.
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. Open your data: Launch WPS Spreadsheet and open your existing Excel workbook containing the employee payment data.
- 2. Format as Table: Highlight your data, navigate to the Home tab, and select 'Format as Table'. Name the table 'tblData'.
- 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.

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.




