Find Sequence Pattern ( + - ) in Data

ibmy

Board Regular
Joined
Mar 4, 2020
Messages
106
Office Version
  1. 2016
Platform
  1. Windows
Hi Mr Excel,

Before I give data sample, let me explain the sequence pattern in picture and the criteria.

pattn.png


Criteria of Sequence Pattern :

(1) Must at least starting with postive number, follow by negative number. ( + - )

(2) Keep assign "1" the cycle until 'invalid' happen ( + - + - + - + - + - ......... )

(3) Invalid,Stop Assign : Posive / Negative number appear two time consecutively. ( + - + - - ) / ( + - + - + - ++ )

(4) Invalid,Stop Assign : 0 appear. ( + - + 0 ) / ( + - + - + - 0 )

plus minus.xlsb
FGHI
1bExpected Result
2
3-0.4
41
50
60.9
7-0.11
8-0.3
90.1
100.1
11-0.11
120.11
130.8
140
150.1
16-0.61
170.71
18-0.91
1911
20-1.61
210.71
220.3
23-0.31
240.11
25-0.61
26-0.3
270.1
28-0.61
29-0.5
300.2
31-0.11
320
330
340
350.1
360.1
37-0.31
38
Sheet6

Expected result in Column H.
Dont mind any method of getting the result ( formula, column helper, vba, etc... ) as long as work fine in 300k row data.

Thanks in advance.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Put in column I to compare
Excel Formula:
=IF(MAX(AND(SIGN(G5)=-1,SIGN(G4)=1)+0,IF(J4=1,AND(SIGN(G5)<>SIGN(G4),SIGN(G5)<>AND(SIGN(G5)=-1,SIGN(G4)=1)+0))+0)=1,1,"")
I built helper columns to step through, but this is the final single column answer.
 
Upvote 0
@C Moore thanks for reply,

I have 2 questions,

1 ) In formula, there is J4 reference, but there is none value in that cell
> I tried change J4 to G4, the result not same

2 ) Which row of "Column I" should I insert the formula?
> I tried insert the formula in I5 after change J4 to G4, the result not same

ab2.xlsb
GHI
1bExpected ResultFormula
2
3-0.4
41
50 
60.9 
7-0.111
8-0.3 
90.1 
100.1 
11-0.111
120.11 
130.8 
140 
150.1 
16-0.611
170.71 
18-0.911
1911 
20-1.611
210.71 
220.3 
23-0.311
240.11 
25-0.611
26-0.3 
270.1 
28-0.611
29-0.5 
300.2 
31-0.111
320 
330 
340 
350.1 
360.1 
37-0.311
Sheet2
Cell Formulas
RangeFormula
I5:I37I5=IF(MAX(AND(SIGN(G5)=-1,SIGN(G4)=1)+0,IF(G4=1,AND(SIGN(G5)<>SIGN(G4),SIGN(G5)<>AND(SIGN(G5)=-1,SIGN(G4)=1)+0))+0)=1,1,"")
 
Upvote 0
See if this does what you want.

23 05 17.xlsm
GH
1bResult
2
3-0.4 
41 
50 
60.9 
7-0.11
8-0.3 
90.1 
100.1 
11-0.11
120.11
130.8 
140 
150.1 
16-0.61
170.71
18-0.91
1911
20-1.61
210.71
220.3 
23-0.31
240.11
25-0.61
26-0.3 
270.1 
28-0.61
29-0.5 
300.2 
31-0.11
320 
330 
340 
350.1 
360.1 
37-0.31
Pattern
Cell Formulas
RangeFormula
H3:H37H3=IF(AND(H2="",G2>0,G3<0),1,IF(AND(H2=1,SIGN(G2)*SIGN(G3)=-1),1,""))
 
Upvote 0
Solution
Thanks @Peter_SSs , the formula working great.

If I want the sequence at least starting negative number follow by postive number, I just change G2<0, G3>0 , right?

gh2.xlsb
GHI
1bStarting - +Starting + -
2
3-0.4  
411 
50  
60.9  
7-0.1 1
8-0.3  
90.11 
100.1  
11-0.1 1
120.111
130.8  
140  
150.1  
16-0.6 1
170.711
18-0.911
19111
20-1.611
210.711
220.3  
23-0.3 1
240.111
25-0.611
26-0.3  
270.11 
28-0.611
29-0.5  
300.21 
31-0.111
320  
330  
340  
350.1  
360.1  
37-0.3 1
Sheet6
Cell Formulas
RangeFormula
H3:H37H3=IF(AND(H2="",G2<0,G3>0),1,IF(AND(H2=1,SIGN(G2)*SIGN(G3)=-1),1,""))
I3:I37I3=IF(AND(I2="",G2>0,G3<0),1,IF(AND(I2=1,SIGN(G2)*SIGN(G3)=-1),1,""))
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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