cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
%3CLINGO-SUB%20id%3D%22lingo-sub-628207%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EAdjustable%20Lag%20Difference%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-628207%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EDon't%20know%20how%20to%20title%20this%20but%20here%20goes.%20I%20have%20data%20sets%20with%20several%20time%20points%20per%20batch.%20For%20each%20batch%20I%20want%20to%20calculate%20the%20difference%20in%20results%20from%20time%20point%20zero.%20I%20used%20to%20compare%20each%20result%20to%20column%20min%20or%20max%20(as%20suitable)%20which%20worked%20fine%2C%20but%20when%20results%20are%20a%20bit%20jumpy%2C%20the%20max%20or%20min%20may%20happen%20at%20another%20time%20point%20than%20zero.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20the%20(desired)%20diff%20as%20below.%20Is%20there%20a%20simple%20way%20to%20do%20this%20in%20a%20formula%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ake_0-1683127236504.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Ake_0-1683127236504.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Ake_0-1683127236504.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F52527i61243B9B9175A74B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Ake_0-1683127236504.png%22%20alt%3D%22Ake_0-1683127236504.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Ejmp%2017.1%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-628207%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EContent%20Organization%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMass%20Customization%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuality%20and%20Process%20Engineering%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharing%20and%20Communicating%20Results%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-628238%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Adjustable%20Lag%20Difference%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-628238%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJust%20adding%20few%20possible%20options%20if%20the%20data%20isn't%20always%20sorted.%3C%2FP%3E%0A%3CP%3EUsing%20matrix%20calculations%20to%20get%20the%20indices%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EAs%20Constant(%0A%20times%20%3D%20%3ATime%20%26lt%3B%26lt%3B%20get%20as%20matrix%3B%0A%20batches%20%3D%20%3ABatch%20%26lt%3B%26lt%3B%20get%20as%20matrix%3B%0A)%3B%0A%0Abatch_rows%20%3D%20Loc(batches%2C%20%3ABatch)%3B%0Abatch_first_time_row%20%3D%20batch_rows%5BLoc%20Min(times%5Bbatch_rows%5D)%5D%3B%0A%3AResult%20-%20%3AResult%5Bbatch_first_time_row%5D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20using%20Col%20Sum%20to%20get%20the%20minimum%20value%20with%20comparison%20and%20product%20(if%20%3ATime%20isn't%20the%20smallest%20multiplier%20is%200).%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3AResult%20-%20Col%20Sum((%3ATime%20%3D%3D%20Col%20Min(%3ATime%2C%20%3ABatch))%20*%20%3AResult%2C%20%3ABatch)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-628237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Adjustable%20Lag%20Difference%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-628237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EEasiest%20way%20(in%20my%20opinion)%20to%20see%20how%20it%20works%20is%20to%20divide%20that%20formula%20into%20three%20different%20formulas%3C%2FP%3E%0A%3CP%3EFirst%20one%20(BatchMinRow)%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ECol%20Min(Row()%2C%20%3ABatch)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESecond%20using%20the%20just%20created%20BatchMinRow%20(BatchMinVal)%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3AResult%5B%3ABatchMinRow%5D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20finally%20third%20one%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3AResult%20-%20%3ABatchMinVal%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Ethis%20makes%20it%20much%20easier%20to%20see%20what%20the%20different%20parts%20in%20the%20formula%20do%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-628236%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Adjustable%20Lag%20Difference%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-628236%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EThanks%20for%20extremely%20fast%2C%20and%20useful%2C%20response!%20I%20will%20ponder%20how%2C%20but%20I%20see%20it%20works!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-628220%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Adjustable%20Lag%20Difference%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-628220%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIf%20the%20results%20are%20ordered%2C%20you%20could%20use%20something%20like%20this%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3AResult%20-%20%3AResult%5BCol%20Min(Row()%2C%20%3ABatch)%5D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ECol%20Min(Row()%2C%20%3ABatch)%20will%20get%20the%20first%20row%20for%20specific%20batch%20and%20then%20we%20can%20access%20that%20row%20by%20using%20%3AResult%5Brownr%5D.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_0-1683129377019.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1683129377019.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1683129377019.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F52529iCEB18B68495316F3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_0-1683129377019.png%22%20alt%3D%22jthi_0-1683129377019.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIf%20the%20data%20isn't%20always%20ordered%20it%20isn't%20really%20a%20problem%2C%20but%20it%20will%20require%20different%20formula%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Ake
Ake
Level III

Adjustable Lag Difference?

Don't know how to title this but here goes. I have data sets with several time points per batch. For each batch I want to calculate the difference in results from time point zero. I used to compare each result to column min or max (as suitable) which worked fine, but when results are a bit jumpy, the max or min may happen at another time point than zero.

 

I want the (desired) diff as below. Is there a simple way to do this in a formula? 

 

Ake_0-1683127236504.png

jmp 17.1

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Adjustable Lag Difference?

If the results are ordered, you could use something like this:

:Result - :Result[Col Min(Row(), :Batch)]

Col Min(Row(), :Batch) will get the first row for specific batch and then we can access that row by using :Result[rownr].

jthi_0-1683129377019.png

If the data isn't always ordered it isn't really a problem, but it will require different formula

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Adjustable Lag Difference?

If the results are ordered, you could use something like this:

:Result - :Result[Col Min(Row(), :Batch)]

Col Min(Row(), :Batch) will get the first row for specific batch and then we can access that row by using :Result[rownr].

jthi_0-1683129377019.png

If the data isn't always ordered it isn't really a problem, but it will require different formula

-Jarmo
Ake
Ake
Level III

Re: Adjustable Lag Difference?

Thanks for extremely fast, and useful, response! I will ponder how, but I see it works!

jthi
Super User

Re: Adjustable Lag Difference?

Easiest way (in my opinion) to see how it works is to divide that formula into three different formulas

First one (BatchMinRow)

Col Min(Row(), :Batch)

Second using the just created BatchMinRow (BatchMinVal)

:Result[:BatchMinRow]

and finally third one

:Result - :BatchMinVal

this makes it much easier to see what the different parts in the formula do

-Jarmo
jthi
Super User

Re: Adjustable Lag Difference?

Just adding few possible options if the data isn't always sorted.

Using matrix calculations to get the indices

 

As Constant(
	times = :Time << get as matrix;
	batches = :Batch << get as matrix;
);

batch_rows = Loc(batches, :Batch);
batch_first_time_row = batch_rows[Loc Min(times[batch_rows])];
:Result - :Result[batch_first_time_row];

and using Col Sum to get the minimum value with comparison and product (if :Time isn't the smallest multiplier is 0).

:Result - Col Sum((:Time == Col Min(:Time, :Batch)) * :Result, :Batch);

 

 

 

-Jarmo

Recommended Articles