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
jeff_gross
Level I

How Can I Get The Lag Function to "Reset" With Each New Batch?

Hello, 

I have the following data and I want to use the Lag function to calculate the difference between each result and the result prior to it (the data table is also attached to this message).

I am using JMP 16.

 

jgross_2-1736542505146.png

Currently I'm using the following formula in the "Difference" column:

jgross_0-1736542408545.png

What I can't figure out is how to get the calculation to "reset" once it gets to Batch B. I realize that even with my current formula, only the difference value in row 16 is incorrect, but still I would know to setup the formula so that it works properly within batches.

Does anyone have any suggestions?

 

Jeff

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How Can I Get The Lag Function to "Reset" With Each New Batch?

change your formula to

If( :"Time Point (months)"n == 0,
	.,
	:Result - Lag( :Result )
)

 

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: How Can I Get The Lag Function to "Reset" With Each New Batch?

change your formula to

If( :"Time Point (months)"n == 0,
	.,
	:Result - Lag( :Result )
)

 

Jim
jeff_gross
Level I

Re: How Can I Get The Lag Function to "Reset" With Each New Batch?

Thank you for the quick replies @txnelson @jthi 

Much appreciated!!

hogi
Level XII

Re: How Can I Get The Lag Function to "Reset" With Each New Batch?

If you need such grouped lag operations frequently, you might have a look at 
https://marketplace.jmp.com/appdetails/Normalization+GUI in the Marketplace.

It implemented the N-1 in combination with grouping based on  @jthi 's approach:

hogi_0-1736585657173.png

 

This takes the pain to remember the exact syntax : )

In addition, the Platform handles Excluded rows automatically.

jthi
Super User

Re: How Can I Get The Lag Function to "Reset" With Each New Batch?

You can also utilize Col Moving Average to get the previous value (Data preparation- substract column data by other column )

:Result- (Col Moving Average(:Result, 1, 1, 0, :Lot Number) * 2 - :Result)

but in your case using something like Jim suggested is most likely better. Also there is Dif function you can use instead of Lag

If( :"Time Point (months)"n == 0,
	.,
	Dif(:Result, 1)
)
-Jarmo