r/excel•
TriggerTay

How to find max value within a range with user inputted range size

solved

I think this is a pretty simple question for you pros.

I have a simple data set with 2 columns (call it A1:B20), one column has date, and one has price.

I would like a formula that tells me the max value within x number of days, with a cell where i can enter a new value for X days in the range. I have my day count in C1 and the max value output in C2

Any help would be greatly appreciated.

Posted Mar 6, 2020, 3:54 PM UTC

38
Rsl12036•

Definitely possible with MAXIFS.

I'd say you need a date range though rather than x number of days. What would an example date range be?

1
TriggerTayOP•

Thanks for responding. The most recent 30 days would be fine.

The real data set is daily financial data and for the last 5 years. Im trying to backtest trading ideas i have, so im not sure entering dates is what im after. I want to say "I have a trading signal in the data, and if this signal had happened in the past, what would my max value be within the next X days".

1
Rsl12036•

That's fine, so today essentially would be one date and today -30 would be the other. This would look like this:

=MAXIFS($B$2:$B$20,$A$2:$A$20,">="&TODAY()-$C$1)

(assuming your columns have headers in A1 & B1)

2
TriggerTayOP•

hey sorry for delay in responding. This helped. I appreciate it.

2
Rsl12036•

No worries - Glad to be of assistance!

1
TriggerTayOP•

Solution Verified

2
Clippy_Office_AsstMOD•

You have awarded 1 point to Rsl120

^I ^am ^a ^bot, ^please ^contact ^the ^mods ^for ^any ^questions.

1
FiLoX45116•

Hi,

what about something like (in C2):

=MAXIFS($B$1:$B$20,$A$1:$A$20,">="&TODAY()-C1)

Hope that helps!

1