Range of formula changes according to a condition

phil133

Active Member
Joined
May 5, 2015
Messages
257
Office Version
  1. 365
Platform
  1. Windows
Hi. The formula STDEV.P(B2:$B$22) calculates the standard deviation of the range b2:b22. This formula works great until row 21. The problem is that in row 22 I would like it to calculate the stdev of range (B22:$B$42) and not B22:B22.
Now, I will try to explain where B42 comes from. Column E has dates. Between E2 and E21 there is the same date. It changes in E22 and stays the same until E41. It changes again in E42. So every time the date in cell E changes I would like this to be the new end row of the range B2:$B$X, where X is the row that the date in cell E changes.
A table to understand. G is the end result
[TABLE="width: 500"]
<tbody>[TR]
[TD]row\column[/TD]
[TD]B[/TD]
[TD]E[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]11[/TD]
[TD]14/2/2006[/TD]
[TD]=STDEV.P(B2:$B$22)[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]12[/TD]
[TD]14/2/2006[/TD]
[TD]=STDEV.P(B3:$B$22)[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]10[/TD]
[TD]14/2/2006[/TD]
[TD]=STDEV.P(B4:$B$22)[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD][/TD]
[TD]14/2/2006[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]21[/TD]
[TD]13[/TD]
[TD]14/2/2006[/TD]
[TD]=STDEV.P(B21:$B$22)[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]14[/TD]
[TD]14/3/2006[/TD]
[TD]=STDEV.P(B22:$B$42)[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD][/TD]
[TD]14/3/2006[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]41[/TD]
[TD]11[/TD]
[TD]14/3/2006[/TD]
[TD]=STDEV.P(B41:$B$42)[/TD]
[/TR]
[TR]
[TD]42[/TD]
[TD]10[/TD]
[TD]18/4/2006[/TD]
[TD]=STDEV.P(B42:$B$67)[/TD]
[/TR]
</tbody>[/TABLE]
G42 has $B$67 because in E67 the date is not 18/4/2006.

Hope you understand what I'm trying to do!
Thanks for any help!
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It would be easy if you just wanted to calculate the standard deviation for each date. It looks like you want to include the last row from the previous date and the first one of the new date in your calculations. Is that correct?
 
Upvote 0
Thank you for your answer Ken! Yes, correct. But what would you do if you just wanted to calculate the standard deviation for each date?

Thank you.
Phil
 
Upvote 0
You would use an array function like

=STDEV.P(IF($A$1:$A$22=A1,$B$1:$B$22,""))

Dates in column A , data in column B. Enter with shift-control-enter to make it an array. You have to drag it down rather than copy it.

To pick up the extra data, last from the previous data and first from the next date, you could probably add a helper column that has that logic built into it and use that column in the nested IF function.

I hope this helps.

Ken
 
Upvote 0
Thank you for your answer Ken. Then problem with this is that it works for the first 22 rows but then (even if we exclude the 1 row that has the problem) it does not continue. For example in row 25 it should be stdev.p(b25:b42) but this formula can't find B42.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,346
Members
452,638
Latest member
Oluwabukunmi

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