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%3EBedingte%20Formel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711204%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20versuche%2C%20eine%20Spaltenformel%20hinzuzuf%C3%BCgen%2C%20die%20von%20anderen%20Spalten%20abh%C3%A4ngig%20ist.%20Ich%20habe%20Daten%2C%20in%20denen%20die%20Spalte%20%E2%80%9EErgebnisse%E2%80%9C%20nach%20%E2%80%9EBetreff%E2%80%9C%20und%20%E2%80%9EProdukt%E2%80%9C%20mit%20mehreren%20Werten%20%C3%BCber%20%E2%80%9EZeit%E2%80%9C%20gestapelt%20ist.%20Ich%20versuche%2C%20die%20Basislinie%20f%C3%BCr%20jeden%20Wert%20in%20%E2%80%9EErgebnisse%E2%80%9C%20zu%20berechnen%2C%20sodass%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENeue%20Spalte%20%3D%20%E2%80%9EErgebnisse%E2%80%9C%20%E2%80%93%20%5BWert%20%E2%80%9EErgebnisse%E2%80%9C%2C%20wobei%20Zeit%3D(1)%20f%C3%BCr%20diese%20bestimmte%20Kombination%20aus%20Betreff%20und%20Produkt%5D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDanke%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%3EAutomatisierung%20und%20Skripterstellung%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%3EBetreff%3A%20Bedingungsformel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711220%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EK%C3%B6nnen%20Sie%20ein%20Beispiel%20f%C3%BCr%20die%20Daten%20nennen%3FDas%20hilft%20bei%20der%20Suche%20nach%20einer%20geeigneten%20L%C3%B6sung.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Bedingungsformel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711237%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EWenn%20Ihre%20Daten%20nach%20Betreff%2C%20Produkt%20und%20Zeit%20sortiert%20sind%2C%20funktioniert%20dieses%20Beispiel%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%3EBetreff%3A%20Bedingungsformel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711335%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20habe%20Beispieldaten%20beigef%C3%BCgt.%20Ich%20muss%20eine%20neue%20Spalte%20hinzuf%C3%BCgen%2C%20in%20der%20die%20Formel%20den%20Zeit(-5)-Ergebniswert%20f%C3%BCr%20jede%20Betreff-%2FProduktkombination%20nimmt%20und%20diesen%20Wert%20von%20jedem%20Ergebnis%20in%20der%20Betreff-%2FProduktkombination%20subtrahiert.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-711362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Bedingungsformel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EManchmal%20ist%20es%20einfacher%2C%20solche%20Probleme%20in%20mehreren%20Schritten%20anzugehen%2C%20als%20komplexe%20JSL%20f%C3%BCr%20eine%20Spaltenformel%20zu%20schreiben.%20Hier%20ist%20ein%20Ansatz%2C%20der%20%E2%80%9ESubset%E2%80%9C%20verwendet%2C%20um%20die%20Time%3D-5-Zeilen%20zu%20extrahieren%2C%20sie%20mit%20%E2%80%9EUpdate%E2%80%9C%20wieder%20mit%20der%20urspr%C3%BCnglichen%20Datentabelle%20zusammenf%C3%BCgt%20und%20dann%20eine%20einfache%20Subtraktion%20in%20einer%20Spaltenformel%20durchf%C3%BChrt.%20Wenn%20Sie%20JMP%2017%20verwenden%2C%20sind%20Workflows%20eine%20gro%C3%9Fartige%20M%C3%B6glichkeit%2C%20solche%20Dinge%20zu%20erstellen%20und%20zu%20teilen.%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%3EBetreff%3A%20Bedingungsformel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711367%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EDie%20JSL%2C%20die%20ich%20mir%20ausgedacht%20habe%2C%20ist%20nicht%20allzu%20kompliziert.Ich%20habe%20keine%20Formel%20geschrieben%2C%20sondern%20ein%20Tabellenskript.Sie%20k%C3%B6nnen%20dies%20immer%20dann%20ausf%C3%BChren%2C%20wenn%20Sie%20weitere%20Daten%20hinzuf%C3%BCgen.%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%3Ebearbeiten%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENachdem%20ich%20mir%20die%20Tabelle%20genauer%20angesehen%20hatte%2C%20fielen%20mir%20die%20fehlenden%20Werte%20in%20einigen%20%3AResults-Zellen%20auf.Sie%20sollten%20diese%20auf%200%20umcodieren%20oder%20das%20Skript%20etwas%20%C3%A4ndern%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%3EBetreff%3A%20Bedingungsformel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-711236%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ENur%20eine%20Vermutung%2C%20da%20es%20keine%20Daten%20gibt%2C%20mit%20denen%20man%20dies%20testen%20k%C3%B6nnte%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%3EBearbeiten%3A%3C%2FP%3E%0A%3CP%3EAktualisierte%20Formel%2C%20nachdem%20wir%20Beispieldaten%20erhalten%20haben%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