<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Conditional Formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711367#M89492</link>
    <description>&lt;P&gt;The JSL I came up with isn't too complicated.&amp;nbsp; I didn't write a formula but a table script.&amp;nbsp; You could run this whenever you add more data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
OffsetArray = Associative Array();
TimeRows = dt &amp;lt;&amp;lt; 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] );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;edit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After looking at the table more, I noticed the missing values in some :Results cells.&amp;nbsp; You should recode those to 0 or alter the script a bit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
OffsetArray = Associative Array();
TimeRows = dt &amp;lt;&amp;lt; 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] );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2023 22:14:23 GMT</pubDate>
    <dc:creator>mmarchandTSI</dc:creator>
    <dc:date>2023-12-20T22:14:23Z</dc:date>
    <item>
      <title>Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711204#M89478</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New Column = "Results" – ["Results" value where Time=(1) for that particular Subject/Product combination]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 15:27:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711204#M89478</guid>
      <dc:creator>JMPUser9</dc:creator>
      <dc:date>2023-12-20T15:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711220#M89481</link>
      <description>&lt;P&gt;Can you give an example of the data?&amp;nbsp; That will help with finding a proper solution.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 15:43:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711220#M89481</guid>
      <dc:creator>mmarchandTSI</dc:creator>
      <dc:date>2023-12-20T15:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711236#M89483</link>
      <description>&lt;P&gt;Just a guess as there is no data to test this with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:Result - Col Min(If(:Time == 1, :Result, .), :Group);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Updated formula after we received sample data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:Results - Col Min(If(:Time == -5, :Results, .), :Subject, :Product)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 05:58:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711236#M89483</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-12-21T05:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711237#M89484</link>
      <description>&lt;P&gt;If your data are sorted by Subject, Product, Time then this example will work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt:age &amp;lt;&amp;lt; set name( "Subject" );
dt:sex &amp;lt;&amp;lt; set name( "Product" );
dt:weight &amp;lt;&amp;lt; set name( "Results" );

dt &amp;lt;&amp;lt; New Column( "baseline",
	formula(
		If( Row() == 1,
			valueTime1 = :Results,
			If( :Subject != Lag( :subject ) | :Product != Lag( :product ),
				valueTime1 = :Results
			)
		);
		baseline = :Results - valueTime1;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2023 16:11:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711237#M89484</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-12-20T16:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711335#M89486</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 20:09:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711335#M89486</guid>
      <dc:creator>JMPUser9</dc:creator>
      <dc:date>2023-12-20T20:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711362#M89489</link>
      <description>&lt;P&gt;Sometimes it's&amp;nbsp; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 21:14:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711362#M89489</guid>
      <dc:creator>Jordan_Hiller</dc:creator>
      <dc:date>2023-12-20T21:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711367#M89492</link>
      <description>&lt;P&gt;The JSL I came up with isn't too complicated.&amp;nbsp; I didn't write a formula but a table script.&amp;nbsp; You could run this whenever you add more data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
OffsetArray = Associative Array();
TimeRows = dt &amp;lt;&amp;lt; 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] );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;edit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After looking at the table more, I noticed the missing values in some :Results cells.&amp;nbsp; You should recode those to 0 or alter the script a bit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
OffsetArray = Associative Array();
TimeRows = dt &amp;lt;&amp;lt; 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] );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 22:14:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Conditional-Formula/m-p/711367#M89492</guid>
      <dc:creator>mmarchandTSI</dc:creator>
      <dc:date>2023-12-20T22:14:23Z</dc:date>
    </item>
  </channel>
</rss>

