cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-711204%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EFormula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711204%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESto%20cercando%20di%20aggiungere%20una%20formula%20di%20colonna%20condizionale%20ad%20altre%20colonne.%20Ho%20dati%20in%20cui%20la%20colonna%20%22Risultati%22%20%C3%A8%20impilata%20per%20%22Oggetto%22%20e%20%22Prodotto%22%20con%20pi%C3%B9%20valori%20su%20%22Tempo%22.%20Sto%20cercando%20di%20calcolare%20la%20linea%20di%20base%20per%20ciascun%20valore%20in%20%22Risultati%22%20in%20modo%20che%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENuova%20colonna%20%3D%20%22Risultati%22%20%E2%80%93%20%5Bvalore%20%22Risultati%22%20dove%20Ora%3D(1)%20per%20quella%20particolare%20combinazione%20Oggetto%2FProdotto%5D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGrazie%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-711204%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EAutomazione%20e%20scripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711220%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Formula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711220%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPuoi%20fornire%20un%20esempio%20dei%20dati%3FCi%C3%B2%20aiuter%C3%A0%20a%20trovare%20una%20soluzione%20adeguata.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Formula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESe%20i%20tuoi%20dati%20sono%20ordinati%20per%20Oggetto%2C%20Prodotto%2C%20Orario%2C%20questo%20esempio%20funzioner%C3%A0%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%2Fbig%20class.jmp%22%20)%3B%0Adt%3Aage%20%26lt%3B%26lt%3B%20set%20name(%20%22Subject%22%20)%3B%0Adt%3Asex%20%26lt%3B%26lt%3B%20set%20name(%20%22Product%22%20)%3B%0Adt%3Aweight%20%26lt%3B%26lt%3B%20set%20name(%20%22Results%22%20)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22baseline%22%2C%0A%20formula(%0A%20%20If(%20Row()%20%3D%3D%201%2C%0A%20%20%20valueTime1%20%3D%20%3AResults%2C%0A%20%20%20If(%20%3ASubject%20!%3D%20Lag(%20%3Asubject%20)%20%7C%20%3AProduct%20!%3D%20Lag(%20%3Aproduct%20)%2C%0A%20%20%20%20valueTime1%20%3D%20%3AResults%0A%20%20%20)%0A%20%20)%3B%0A%20%20baseline%20%3D%20%3AResults%20-%20valueTime1%3B%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711335%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Formula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711335%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHo%20incluso%20dati%20di%20esempio.%20Devo%20aggiungere%20una%20nuova%20colonna%20in%20cui%20la%20formula%20prende%20il%20valore%20dei%20risultati%20Time(-5)%20per%20ciascuna%20combinazione%20oggetto%2Fprodotto%20e%20sottrae%20tale%20valore%20da%20ciascun%20risultato%20nella%20combinazione%20oggetto%2Fprodotto.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Formula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EA%20volte%20%C3%A8%20pi%C3%B9%20semplice%20affrontare%20problemi%20come%20questo%20in%20pi%C3%B9%20passaggi%2C%20piuttosto%20che%20scrivere%20un%20jsl%20complesso%20per%20una%20formula%20di%20colonna.%20Ecco%20un%20approccio%20che%20utilizza%20%22Sottoinsieme%22%20per%20estrarre%20le%20righe%20Time%3D-5%2C%20le%20unisce%20nuovamente%20alla%20tabella%20dati%20originale%20con%20%22Aggiorna%22%20e%20quindi%20esegue%20una%20semplice%20sottrazione%20in%20una%20formula%20di%20colonna.%20Se%20utilizzi%20JMP%2017%2C%20i%20flussi%20di%20lavoro%20sono%20un%20ottimo%20modo%20per%20creare%20e%20condividere%20questo%20genere%20di%20cose.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711367%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Formula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711367%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIl%20JSL%20che%20ho%20creato%20non%20%C3%A8%20troppo%20complicato.Non%20ho%20scritto%20una%20formula%20ma%20uno%20script%20di%20tabella.Puoi%20eseguirlo%20ogni%20volta%20che%20aggiungi%20pi%C3%B9%20dati.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Current%20Data%20Table()%3B%0AOffsetArray%20%3D%20Associative%20Array()%3B%0ATimeRows%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20Rows%20Where(%20%3ATime%20%3D%3D%20-5%20)%3B%0AFor%20Each(%20%7Bval%2C%20idx%7D%2C%20TimeRows%2C%20OffsetArray%5B%3ASubject%5Bval%5D%20%7C%7C%20%3AProduct%5Bval%5D%5D%20%3D%20%3AResults%5Bval%5D%20)%3B%0AFor%20Each%20Row(%20dt%2C%20%3ANew%20Column%20%3D%20%3AResults%20-%20OffsetArray%5B%3ASubject%20%7C%7C%20%3AProduct%5D%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Emodificare%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDopo%20aver%20esaminato%20pi%C3%B9%20attentamente%20la%20tabella%2C%20ho%20notato%20i%20valori%20mancanti%20in%20alcune%20celle%20%3AResults.Dovresti%20ricodificarli%20su%200%20o%20modificare%20leggermente%20lo%20script%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Current%20Data%20Table()%3B%0AOffsetArray%20%3D%20Associative%20Array()%3B%0ATimeRows%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20Rows%20Where(%20%3ATime%20%3D%3D%20-5%20)%3B%0AFor%20Each(%20%7Bval%2C%20idx%7D%2C%20TimeRows%2C%20OffsetArray%5B%3ASubject%5Bval%5D%20%7C%7C%20%3AProduct%5Bval%5D%5D%20%3D%20If(%20!Is%20Missing(%20%3AResults%5Bval%5D%20)%2C%20%3AResults%5Bval%5D%2C%200%20)%20)%3B%0AFor%20Each%20Row(%20dt%2C%20%3AResults%20with%20Offset%20%3D%20%3AResults%20-%20OffsetArray%5B%3ASubject%20%7C%7C%20%3AProduct%5D%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711236%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Formula%20condizionale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711236%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C3%88%20solo%20un'ipotesi%20poich%C3%A9%20non%20ci%20sono%20dati%20con%20cui%20testarlo%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3AResult%20-%20Col%20Min(If(%3ATime%20%3D%3D%201%2C%20%3AResult%2C%20.)%2C%20%3AGroup)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EModificare%3A%3C%2FP%3E%0A%3CP%3EFormula%20aggiornata%20dopo%20aver%20ricevuto%20i%20dati%20di%20esempio%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3AResults%20-%20Col%20Min(If(%3ATime%20%3D%3D%20-5%2C%20%3AResults%2C%20.)%2C%20%3ASubject%2C%20%3AProduct)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
JMPUser9
Level II

Conditional Formula

I am trying to add a column formula that is conditional to other columns. I have data where “Results” Column is stacked by “Subject” and “Product” with multiple values over “Time”. I’m trying to calculate the baseline for each value in “Results” so that:

 

New Column = "Results" – ["Results" value where Time=(1) for that particular Subject/Product combination]

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Conditional Formula

Sometimes it's  easier to attack problems like this in several steps, rather than writing complex jsl for a column formula. Here's an approach that uses "Subset" to extract the Time=-5 rows, joins them back onto the original data table with "Update", and then performs a simple subtraction in a column formula. If you're running JMP 17, workflows are a great way to build and share this kind of thing.

 

View solution in original post

6 REPLIES 6
mmarchandTSI
Level V

Re: Conditional Formula

Can you give an example of the data?  That will help with finding a proper solution.

jthi
Super User

Re: Conditional Formula

Just a guess as there is no data to test this with

:Result - Col Min(If(:Time == 1, :Result, .), :Group);

 

Edit:

Updated formula after we received sample data

:Results - Col Min(If(:Time == -5, :Results, .), :Subject, :Product)

 

-Jarmo
txnelson
Super User

Re: Conditional Formula

If your data are sorted by Subject, Product, Time then this example will work

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt:age << set name( "Subject" );
dt:sex << set name( "Product" );
dt:weight << set name( "Results" );

dt << New Column( "baseline",
	formula(
		If( Row() == 1,
			valueTime1 = :Results,
			If( :Subject != Lag( :subject ) | :Product != Lag( :product ),
				valueTime1 = :Results
			)
		);
		baseline = :Results - valueTime1;
	)
);
Jim
JMPUser9
Level II

Re: Conditional Formula

I've included sample data. I need to add a new column where the formula takes the Time(-5) Results value for each Subject/Product combination and subtracts that value from each Result in the Subject/Product Combination. 

Re: Conditional Formula

Sometimes it's  easier to attack problems like this in several steps, rather than writing complex jsl for a column formula. Here's an approach that uses "Subset" to extract the Time=-5 rows, joins them back onto the original data table with "Update", and then performs a simple subtraction in a column formula. If you're running JMP 17, workflows are a great way to build and share this kind of thing.

 

mmarchandTSI
Level V

Re: Conditional Formula

The JSL I came up with isn't too complicated.  I didn't write a formula but a table script.  You could run this whenever you add more data.

 

dt = Current Data Table();
OffsetArray = Associative Array();
TimeRows = dt << Get Rows Where( :Time == -5 );
For Each( {val, idx}, TimeRows, OffsetArray[:Subject[val] || :Product[val]] = :Results[val] );
For Each Row( dt, :New Column = :Results - OffsetArray[:Subject || :Product] );

edit

 

After looking at the table more, I noticed the missing values in some :Results cells.  You should recode those to 0 or alter the script a bit:

 

dt = Current Data Table();
OffsetArray = Associative Array();
TimeRows = dt << Get Rows Where( :Time == -5 );
For Each( {val, idx}, TimeRows, OffsetArray[:Subject[val] || :Product[val]] = If( !Is Missing( :Results[val] ), :Results[val], 0 ) );
For Each Row( dt, :Results with Offset = :Results - OffsetArray[:Subject || :Product] );

 

Recommended Articles