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
Ohad_s
Level III

How to Count rows based on difference between values in a column ?

Hi,

I am trying to create a new column based on column "DieY"

I want continuous count based on the difference between each row and the previous one.

row 2-row 1, row 3-row 2, row 4-row 3 and so on.

if the difference is below a certain value, e.g. 5, set the value to 1.

if the difference is above, add 1 to the count.

keep the last count until the difference is above the value set in the formula.

so eventually I will have a new column with values such as: 1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3 and so on..

 

Many thanks to any help

 

Ohad_s_0-1727735727384.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to Count rows based on difference between values in a column ?

Here is the formula I came up with

If(
	Row() == 1, count = 1,
	:DieY - Lag( :DieY ) > 5, count
	++);
count;

txnelson_0-1727770895361.png

 

Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: How to Count rows based on difference between values in a column ?

Here is the formula I came up with

If(
	Row() == 1, count = 1,
	:DieY - Lag( :DieY ) > 5, count
	++);
count;

txnelson_0-1727770895361.png

 

Jim