Median of the last 7 non-blank values, offset from a cell

MatrixBS

New Member
Joined
Apr 3, 2017
Messages
1
All,

I've scoured the internet looking for an answer to this problem, but am left unsatisfied. Maybe i'm over complicating things, & I hope someone can help me out.

I currently have a spreadsheet that is updated on a monthly basis where I need to calculate the median of the last 7 reportable (i.e. non-zero) values prior to my current data. I cannot simply "remove blanks" as I have additional pertinent information on adjacent columns. Here's a sample dataset:

ABC
11/1/1610.2
22/1/1653
33/1/16156
44/1/169
55/1/1615
66/1/16424
77/1/16517
88/1/1610
99/1/162
1010/1/163
1111/1/1615
1212/1/160.556
131/1/1754
142/1/17113
153/1/17139
164/1/17171
17Median of last 7 valueFORMULA? 9

<tbody>
</tbody>

Assuming 4/1/17 is my current dataset, I need to calculate the median of the last 7 data points in column B prior to 4/1/17 (i.e. last 7 values from 1/1/16 through 3/1/17 [rows 1 through 15]) to compare to my current data. I am using the array formula:

=MEDIAN(INDIRECT("B"&LARGE(ISNUMBER(B1:B15)*ROW(B1:B15),7)&":B15"))

which ultimately calculates the correct result, but that array formula is cumbersome. I also have thousands of these discrete datasets where the "B" in INDIRECT("B" and the ":B15") at the end of the formula don't carry when I copy from row-to-row and column-to-column. Is there a more elegant (preferably non-array) formula I can use that I haven't thought of?

As an added bonus, is there any way I could make the formula automatically update as I insert data for 5/1/17 and beyond (i.e. insert data into row 17)?

Thank you for all of the help I've gotten over the years from the experts at Mr.Excel.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,

Is the following (with a helper column) any better than what you already have?

J.Ty.


Excel 2016 (Windows) 64 bit
ABCDE
1iddatenumberinfo9
2101.01.201610.28
3202.01.2016537
4303.01.20161566
5404.01.201696
6505.01.2016156
7606.01.20164245
8707.01.20165174
9808.01.2016104
10909.01.201624
111010.01.201634
121111.01.2016154
131212.01.20160.5563
141301.01.2017543
151402.01.20171132
161503.01.20171391
171604.01.20171710
1817Median of last 7 value119
Sheet2
Cell Formulas
RangeFormula
E1=IF(ISNUMBER(C2),1+E2,E2)
E2=IF(ISNUMBER(C3),1+E3,E3)
E3=IF(ISNUMBER(C4),1+E4,E4)
E4=IF(ISNUMBER(C5),1+E5,E5)
E5=IF(ISNUMBER(C6),1+E6,E6)
E6=IF(ISNUMBER(C7),1+E7,E7)
E7=IF(ISNUMBER(C8),1+E8,E8)
E8=IF(ISNUMBER(C9),1+E9,E9)
E9=IF(ISNUMBER(C10),1+E10,E10)
E10=IF(ISNUMBER(C11),1+E11,E11)
E11=IF(ISNUMBER(C12),1+E12,E12)
E12=IF(ISNUMBER(C13),1+E13,E13)
E13=IF(ISNUMBER(C14),1+E14,E14)
E14=IF(ISNUMBER(C15),1+E15,E15)
E15=IF(ISNUMBER(C16),1+E16,E16)
E16=IF(ISNUMBER(C17),1+E17,E17)
C18=MEDIAN(INDEX(C1:C17,MATCH(0,E1:E17,0)), INDEX(C1:C17,MATCH(1,E1:E17,0)), INDEX(C1:C17,MATCH(2,E1:E17,0)), INDEX(C1:C17,MATCH(3,E1:E17,0)), INDEX(C1:C17,MATCH(4,E1:E17,0)), INDEX(C1:C17,MATCH(5,E1:E17,0)), INDEX(C1:C17,MATCH(6,E1:E17,0)) )
 
Upvote 0
What is the expected value? If 9, that seems to be related to range in column C while your non-working formula refers to the range in column B!...
 
Upvote 0
What is the expected value? If 9, that seems to be related to range in column C while your non-working formula refers to the range in column B!...

Aladin,

Column C is definitely not the intended results. Look at rows 3, 4 and 5. According to the OP the value of the formula should not change, because there are no new values in column B, while the values in column C do change.

J.Ty.
 
Upvote 0
Thanks T.Ty for clarification.

Sheet1 (data plus processing)

Row\Col
A​
B​
C​
1​
1/1/2016
1
0
2​
2/1/2016
5
3
3​
3/1/2016
15
6
4​
4/1/2016
9
5​
5/1/2016
15
6​
6/1/2016
4
24
7​
7/1/2016
5
17
8​
8/1/2016
10
9​
9/1/2016
2
10​
10/1/2016
3
11​
11/1/2016
15
12​
12/1/2016
1
56
13​
1/1/2017
54
14​
2/1/2017
11
3
15​
3/1/2017
13
9
16​
4/1/2017
17
1
17​
Median of last 7 value
5

Define the following names one by one in Formulas | Name Manager.

Drow as referring to:

=MATCH(9.99999999999999E+307,Sheet1!$A:$A)-1

Data as referring to:

=Sheet1!$B$1:INDEX(Sheet1!$B:$B,Drow)

Now we can invoke in the last row, cuurently in B17...

=MEDIAN(IF(ROW(Data)>=LARGE(IF(ISNUMBER(Data),ROW(Data)),MIN(7,SUM(IF(ISNUMBER(Data),1)))),IF(ISNUMBER(Data),Data)))

Note that this set up will adjust itself dynamically to adding new records in-between the end of the data and the formula cell.
 
Upvote 0

Forum statistics

Threads
1,215,184
Messages
6,123,533
Members
449,106
Latest member
techog

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