Calculate Median in a filtered list

metricsman

New Member
Joined
Sep 26, 2002
Messages
10
How can I find the median in a filtered list of numbers?
I don't see median as a function of subtotal.

Thanks in advance.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
If your list is in A2:A100 try this formula [edited]

=MEDIAN(IF(SUBTOTAL(2,OFFSET(A2,ROW(A2:A100)-ROW(A2),0)),A2:A100))

confirmed with CTRL+SHIFT+ENTER
 
Last edited:
Upvote 0
If I'm understanding you correctly, you could employ a workaround I've used numerous times before with subtotals.

Perform your subtotal and then minimize the view so that you just see the subtotaled rows. Highlight these cells, click on edit, go to , special, and click on visible cells only.

It will now highlight the subtotaled data cells only - you could then paste this data into other cells/worksheets in order to perform the calculations you're looking for...
 
Upvote 0
Thanks for the responses. All are great workarounds.
It would be much easier if the median could be calculated on only the displayed items in a filtered list.
 
Upvote 0
This part

=ROW(A2:A100)-ROW(A2)

returns an array of all integers from 0 to 99 so the OFFSET part

=OFFSET(A2,ROW(A2:A100)-ROW(A2),0))

returns an array of single cell ranges A2 through to A100

and then SUBTOTAL with a first argument of 2 (count) will then count the non-filtered numbers in each range (or each cell as the ranges are only single cells)

So for every cell you get 1, if the cell contains a number and isn't filtered out, zero otherwise, and therefore the IF function returns either the number, if unfiltered, or FALSE. Median then calculates, ignoring FALSE entries.

See here too
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top