<?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: How to apply mathematical operations to selected rows only? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534543#M75712</link>
    <description>&lt;P&gt;Thanks a lot Jim, for showing multiple ways to solve this problem! Your help is greatly appreciated!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2022 02:54:19 GMT</pubDate>
    <dc:creator>Bluegalaxy</dc:creator>
    <dc:date>2022-08-17T02:54:19Z</dc:date>
    <item>
      <title>How to apply mathematical operations to selected rows only?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534518#M75710</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am new to JMP and struggling to calculate % change in current for 5 different devices after 72hrs of stress testing as shown in the table below. The % change in current is calculated as = (current @ a given stress duration&amp;nbsp;- current&amp;nbsp;@ 0hr)/current&amp;nbsp;@0hr*100&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bluegalaxy_0-1660695653749.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/44821iF799A195CB5D23F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bluegalaxy_0-1660695653749.png" alt="Bluegalaxy_0-1660695653749.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This operation is quite straightforward in Excel but not sure how to apply the formula to selective rows? Any help will be greatly appreciated! I am using JMP15.0 version.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:53:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534518#M75710</guid>
      <dc:creator>Bluegalaxy</dc:creator>
      <dc:date>2023-06-10T23:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply mathematical operations to selected rows only?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534540#M75711</link>
      <description>&lt;P&gt;Below are 3 methods for doing what you want.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1660701431227.png" style="width: 722px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/44822iEF890F598A207B97/image-dimensions/722x570?v=v2" width="722" height="570" role="button" title="txnelson_0-1660701431227.png" alt="txnelson_0-1660701431227.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Data Table( "Bluegalaxy" );

// Method 1
dt &amp;lt;&amp;lt; New Column( "% Change 1",
	Format( "Percent", 9, 2 ),
	set each value(
		currDevice = :Device Number;
		zeroCurrent = :Current[((dt &amp;lt;&amp;lt; get rows where(
			:Device Number == currDevice &amp;amp; :Stress Duration == 0
		))[1])];
		value = (:Current - zeroCurrent) / zeroCurrent;
	)
);

// Method 2
// Sort the table in assending Device Number/Stress Duration
dt &amp;lt;&amp;lt; sort(
	By( :Device Number, Stress Duration ),
	order( Ascending, Assending ),
	Replace Table( 0 )
);
dt &amp;lt;&amp;lt; New Column( "% Change 2",
	Format( "Percent", 9, 2 ),
	set each value(
		If( :Stress Duration == 0,
			zeroCurrent = :Current
		);
		(:Current - zeroCurrent) / zeroCurrent;
	)
);
// Sort the table back to the original order
dt &amp;lt;&amp;lt; sort(
	By( :Stress Duration, Device Number ),
	order( Ascending, Assending ),
	Replace Table( 0 )
);

// Method 3
// Create a data table with only the 0 Stress Duration values
dt &amp;lt;&amp;lt; Select Where( :Stress Duration == 0 );
dtZero = dt &amp;lt;&amp;lt; subset( selected rows( 1 ), columns( :device Number, :current ) );
dtZero:current &amp;lt;&amp;lt; set name( "zeroCurrent" );
dt &amp;lt;&amp;lt; Update( With( dtZero ), Match Columns( :Device Number = :Device Number ) );
dt &amp;lt;&amp;lt; New Column( "% Change 3",
	Format( "Percent", 9, 2 ),
	set each value( (:Current - :zeroCurrent) / :zeroCurrent )
);
// Clean up 
dt &amp;lt;&amp;lt; delete columns( zeroCurrent );
Close( dtZero, nosave );
dt &amp;lt;&amp;lt; clear select;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All of these methods can be created in an interactive mode.&lt;/P&gt;
&lt;P&gt;Note:&amp;nbsp; I am using "Set Each Value" in the specification of the new columns.&amp;nbsp; This can be swapped out for "Formula".&amp;nbsp; The Formula specification allows for any new records to have the formula applied when they are added, or changed.&amp;nbsp; In the case you have presented, I am assuming that you will want the values created only once, when the new column is created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 02:01:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534540#M75711</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-08-17T02:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply mathematical operations to selected rows only?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534543#M75712</link>
      <description>&lt;P&gt;Thanks a lot Jim, for showing multiple ways to solve this problem! Your help is greatly appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 02:54:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-mathematical-operations-to-selected-rows-only/m-p/534543#M75712</guid>
      <dc:creator>Bluegalaxy</dc:creator>
      <dc:date>2022-08-17T02:54:19Z</dc:date>
    </item>
  </channel>
</rss>

