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%3EFormule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711204%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJ'essaie%20d'ajouter%20une%20formule%20de%20colonne%20conditionnelle%20aux%20autres%20colonnes.%20J'ai%20des%20donn%C3%A9es%20dans%20lesquelles%20la%20colonne%20%C2%AB%20R%C3%A9sultats%20%C2%BB%20est%20empil%C3%A9e%20par%20%C2%AB%20Sujet%20%C2%BB%20et%20%C2%AB%20Produit%20%C2%BB%20avec%20plusieurs%20valeurs%20sur%20%C2%AB%20Temps%20%C2%BB.%20J'essaie%20de%20calculer%20la%20ligne%20de%20base%20pour%20chaque%20valeur%20dans%20%C2%AB%26nbsp%3BR%C3%A9sultats%26nbsp%3B%C2%BB%20afin%20que%26nbsp%3B%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENouvelle%20colonne%20%3D%20%22R%C3%A9sultats%22%20%E2%80%93%20%5Bvaleur%20%22R%C3%A9sultats%22%20o%C3%B9%20Temps%20%3D%20(1)%20pour%20cette%20combinaison%20Sujet%2FProduit%20particuli%C3%A8re%5D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMerci%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%3EAutomatisation%20et%20scripts%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%3ERe%20%3A%20Formule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711220%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPouvez-vous%20donner%20un%20exemple%20des%20donn%C3%A9es%20%3FCela%20aidera%20%C3%A0%20trouver%20une%20solution%20appropri%C3%A9e.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Formule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESi%20vos%20donn%C3%A9es%20sont%20tri%C3%A9es%20par%20Sujet%2C%20Produit%2C%20Heure%20alors%20cet%20exemple%20fonctionnera%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%3ERe%20%3A%20Formule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711335%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJ'ai%20inclus%20des%20exemples%20de%20donn%C3%A9es.%20Je%20dois%20ajouter%20une%20nouvelle%20colonne%20dans%20laquelle%20la%20formule%20prend%20la%20valeur%20des%20r%C3%A9sultats%20Temps%20(-5)%20pour%20chaque%20combinaison%20Sujet%2FProduit%20et%20soustrait%20cette%20valeur%20de%20chaque%20r%C3%A9sultat%20de%20la%20combinaison%20Sujet%2FProduit.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Formule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EParfois%2C%20il%20est%20plus%20facile%20d'attaquer%20des%20probl%C3%A8mes%20comme%20celui-ci%20en%20plusieurs%20%C3%A9tapes%2C%20plut%C3%B4t%20que%20d'%C3%A9crire%20du%20JSL%20complexe%20pour%20une%20formule%20de%20colonne.%20Voici%20une%20approche%20qui%20utilise%20%22Subset%22%20pour%20extraire%20les%20lignes%20Time%3D-5%2C%20les%20joint%20%C3%A0%20la%20table%20de%20donn%C3%A9es%20d'origine%20avec%20%22Update%22%2C%20puis%20effectue%20une%20simple%20soustraction%20dans%20une%20formule%20de%20colonne.%20Si%20vous%20utilisez%20JMP%2017%2C%20les%20workflows%20constituent%20un%20excellent%20moyen%20de%20cr%C3%A9er%20et%20de%20partager%20ce%20genre%20de%20choses.%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%3ERe%20%3A%20Formule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711367%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELe%20JSL%20que%20j'ai%20propos%C3%A9%20n'est%20pas%20trop%20compliqu%C3%A9.Je%20n'ai%20pas%20%C3%A9crit%20de%20formule%20mais%20un%20script%20de%20table.Vous%20pouvez%20l'ex%C3%A9cuter%20chaque%20fois%20que%20vous%20ajoutez%20plus%20de%20donn%C3%A9es.%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%3Emodifier%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EApr%C3%A8s%20avoir%20regard%C3%A9%20davantage%20le%20tableau%2C%20j'ai%20remarqu%C3%A9%20les%20valeurs%20manquantes%20dans%20certaines%20cellules%20%3AResults.Vous%20devriez%20les%20recoder%20%C3%A0%200%20ou%20modifier%20un%20peu%20le%20script%26nbsp%3B%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%3ERe%20%3A%20Formule%20conditionnelle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711236%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJuste%20une%20supposition%20car%20il%20n'y%20a%20pas%20de%20donn%C3%A9es%20pour%20tester%20cela%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%3EModifier%3A%3C%2FP%3E%0A%3CP%3EFormule%20mise%20%C3%A0%20jour%20apr%C3%A8s%20r%C3%A9ception%20d'%C3%A9chantillons%20de%20donn%C3%A9es%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