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
row\columnBEG
21114/2/2006=STDEV.P(B2:$B$22)
31214/2/2006=STDEV.P(B3:$B$22)
41014/2/2006=STDEV.P(B4:$B$22)
...14/2/2006
211314/2/2006=STDEV.P(B21:$B$22)
221414/3/2006=STDEV.P(B22:$B$42)
...14/3/2006
411114/3/2006=STDEV.P(B41:$B$42)
421018/4/2006=STDEV.P(B42:$B$67)

<tbody>
</tbody>
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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,217,381
Messages
6,136,229
Members
450,000
Latest member
jgp19

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