简体   繁体   中英

Dynamic range based on values in another cell

I will lay out the question I currently have. I have an excel sheet in which column A is Date-type data, Column F is returns data, say returns of S&P500 (for examples sake). I have two cells, say G1 and G2, which have arbitrary start and end dates, respectively.

I want to be able to dynamically calculate the standard deviation of the returns data (Column F), with the start date and end date of the range of the standard deviation being equal to cells G1 and G2 respectively. Therefore, as I change cells G1 and G2, it will calculate a different standard deviation, as the range of the function will change.

I have already tried using an offset function, but have had difficulty in making the range dynamic in the sense that, if I just had a set start date, and was interested in changing the number of days to include in the range, I could do that.

The formula would look something like = STDEV.S(OFFSET(A4,1, 5, G3, 1)) where G3 is the number of days looking forward I want to include in the range.

This does not allow me to change the dates in interest as I please.

If I haven't explained something enough, please let me know.

Best,

If your data or first date in Column A starts from Row 4 , then

try replace the first 1 in your OFFSET function to the following:

=MATCH($G$1,$A$4:$A$100,0)-1

Replace $A$4:$A$100 with the actual range of the dates in your Column A,

Then your formula will be something like:

=STDEV.S(OFFSET(A4,MATCH($G$1,$A$4:$A$100,0)-1, 5, G3+1))

or

=STDEV.S(OFFSET(A4,MATCH($G$1,$A$4:$A$100,0)-1, 5, (G2-G1)+1))

The logic is to use MATCH function to return the starting row position based on the start date from cell G1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM