Determining Which of Two Conditions Are Met First

purple

New Member
Joined
Jun 2, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have a data set of stock prices where each line represents a day and has a price.
DatePrice
6/1/1987122.35
6/2/1987119.98

For each row, I want to determine which condition is eventually met first: the price increased by 10%, or it decreased by 5%.

Can someone please help me with a formula (or formulas)? I have no idea of how to do this.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the MrExcel forums!

Consider:

Book3
ABCD
1DatePriceFirst exceeds 10%
26/1/1987122.357
36/2/1987119.98First falls below 5%
46/3/1987109.114
56/4/1987120.2
66/5/1987130.11
76/6/1987135.88
86/7/1987131.88
9
Sheet9
Cell Formulas
RangeFormula
D2D2=AGGREGATE(15,6,ROW(A2:A100)/(B2:B100>=B2*1.1),1)
D4D4=AGGREGATE(15,6,ROW(A2:A100)/(B2:B100<=B2*0.95)/(B2:B100<>""),1)


The D2 and D4 formulas return the row number. If the dates are always increasing, like your example, we can show the date instead.
 
Upvote 0
Thank you, Eric!

The dates will indeed be sequential (ascending).

So if I'm kind of understanding, I think that each row would have these two new columns (D2 and D4), and it can return the date. I'm guessing that a third column would be needed to indicate which event happened first.
 
Upvote 0
Hi Eric, I figured out how to compare the two. I wasn't thinking - it actually didn't need the date, row number was sufficient.

=IF(C2 < D2, "gain", "loss")

However, can you please help me figure out how to handle when the formulas finding the condition return #NUM!? For example, for some prices, the price don't ever seem to meet the -5% again.
 
Upvote 0
Do you mean something like this?

Cell Formulas
RangeFormula
C2:C11C2=AGGREGATE(15,6,ROW(A2:A100)/(B2:B100>=B2*1.1),1)
D2:D11D2=AGGREGATE(15,6,ROW(A2:A100)/(B2:B100<=B2*0.95)/(B2:B100<>""),1)
E2:E11E2=IF(ISERROR(C2)*ISERROR(D2),"Price never exceeds the 15% spread in the remaining rows",IF(IFERROR(C2,2^99)<IFERROR(D2,2^99),"Gain of 10% over "&B2&" achieved on row "&C2,"Loss of 5% from "&B2&" achieved on row "&D2))
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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