cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
yew1992
Level II

How do i sum up number of consecutive values within the same column?

Hi,

 

I was able to identify consecutive values on a column "Data" (Refer to " sequence roll" column). However i need to generate a column (refer to Expected Result column) to sum up the number of consecutive values.

Any help or advice will be appreciate. Thank you

 

 

" sequence roll" column

If( :Item == Lag( :Item, 1 ),
If( Dif( :Data, 1 ) == 1,
Dif( :Data, 1 ), .
), .
)

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do i sum up number of consecutive values within the same column?

I would create two columns, Sequence with formula such as 

As Constant(seq = 0);
If(Dif(:Data) != 1, 
	seq++
);
seq;

and then use that for calculations using Col Number

Col Number(:Sequence, :Sequence)

jthi_2-1731569510585.png

If you want to make first row missing, you can do that by adding if statement to result

If(Row() == Col Min(Row(), :Sequence),
	.
,
	Col Number(:Sequence, :Sequence)
)

jthi_3-1731569602813.png

 

-Jarmo

View solution in original post

5 REPLIES 5
yew1992
Level II

Re: How do i sum up number of consecutive values within the same column?

yew1992_0-1731568830324.png

 

jthi
Super User

Re: How do i sum up number of consecutive values within the same column?

Is there a specific reason of dropping out the value from first matching row while still adding it to the calculation?

 

Here you have 5 consecutive values but first row is set as missing.

jthi_1-1731569333044.png

 

-Jarmo
jthi
Super User

Re: How do i sum up number of consecutive values within the same column?

I would create two columns, Sequence with formula such as 

As Constant(seq = 0);
If(Dif(:Data) != 1, 
	seq++
);
seq;

and then use that for calculations using Col Number

Col Number(:Sequence, :Sequence)

jthi_2-1731569510585.png

If you want to make first row missing, you can do that by adding if statement to result

If(Row() == Col Min(Row(), :Sequence),
	.
,
	Col Number(:Sequence, :Sequence)
)

jthi_3-1731569602813.png

 

-Jarmo
yew1992
Level II

Re: How do i sum up number of consecutive values within the same column?

It works!

Thank you

yew1992_0-1731575448644.png

 

yew1992
Level II

Re: How do i sum up number of consecutive values within the same column?

Hi,

 

No specific reason. Just that my formula to check sequence roll is depending on the previous row above.