<?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: Calculating Percentage difference for a big amount of data in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212274#M42491</link>
    <description>&lt;P&gt;If I understand what you want, I think this is the simplest way to do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();

dt2 = dt &amp;lt;&amp;lt; subset(
	Rows( dt &amp;lt;&amp;lt; get rows where( Time == 0 ) ),
	columns( {"id", "Part", "Value1"} )
);

dt2:Value1 &amp;lt;&amp;lt; set name( "divisor" );

dtJoin = dt &amp;lt;&amp;lt; Join(
	With( dt2 ),
	Merge Same Name Columns,
	Match Flag( 0 ),
	By Matching Columns( :id = :id, :Part = :Part ),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 1, 0 ),
	Preserve main table order( 1 )
);

Close( dt2, nosave );

dtJoin &amp;lt;&amp;lt; New Column( "Value2",
	Numeric,
	"Continuous",
	Format( "Percent", 10, 4 ),
	Formula( (:Value1 - :divisor) / :divisor )
);

dtJoin:Value2 &amp;lt;&amp;lt; delete property( "formula" );
dtJoin &amp;lt;&amp;lt; delete columns( "divisor" );
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Jun 2019 04:07:31 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2019-06-07T04:07:31Z</dc:date>
    <item>
      <title>Calculating Percentage difference for a big amount of data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212262#M42489</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="snipe.PNG" style="width: 304px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/17671iC31773BF42F609AE/image-dimensions/304x487?v=v2" width="304" height="487" role="button" title="snipe.PNG" alt="snipe.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hi everyone!&amp;nbsp;&lt;BR /&gt;I have attached a example file under this post.&lt;BR /&gt;I'm currently trying to calculate the percentage of difference,&lt;BR /&gt;which is given by (New Value- Original Value)/Original Value&lt;BR /&gt;In this case, Time 0 is taken as the reference ( Original Value).&lt;BR /&gt;&amp;nbsp;For example:&lt;BR /&gt;Time: 0, Part: 1 Value 1: 690.2&lt;BR /&gt;Time: 50, Part:1, Value1: 690.52&lt;BR /&gt;(690.52-690.2)/(690.2) = 0.046%&lt;BR /&gt;Time: 100, Part:1, Value1:689.25&lt;BR /&gt;(689.25-690.2)/(690.2)= -0.13%&lt;BR /&gt;The result I'm suppose to get is to have a new table with the Time, id, Part unchanged,&lt;BR /&gt;while having the new values of Value 1 and Value 2 in percentage format.&amp;nbsp;&lt;BR /&gt;I have thought of moving the Different Time values into different tables,&lt;BR /&gt;then compute it against the Time 0 and append it to a new table, but I have no clue on&amp;nbsp;&lt;BR /&gt;how to write it on script.&amp;nbsp;&lt;BR /&gt;I have written some script in the "Percentage Different Progress" file, but I'm stuck.&lt;BR /&gt;I really appreciate it if anyone could help me in this.&amp;nbsp;&lt;BR /&gt;Thank you so so much in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 427px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/17672i41D94078494E7D5F/image-dimensions/427x98?v=v2" width="427" height="98" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 02:44:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212262#M42489</guid>
      <dc:creator>Jax</dc:creator>
      <dc:date>2019-06-07T02:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Percentage difference for a big amount of data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212274#M42491</link>
      <description>&lt;P&gt;If I understand what you want, I think this is the simplest way to do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();

dt2 = dt &amp;lt;&amp;lt; subset(
	Rows( dt &amp;lt;&amp;lt; get rows where( Time == 0 ) ),
	columns( {"id", "Part", "Value1"} )
);

dt2:Value1 &amp;lt;&amp;lt; set name( "divisor" );

dtJoin = dt &amp;lt;&amp;lt; Join(
	With( dt2 ),
	Merge Same Name Columns,
	Match Flag( 0 ),
	By Matching Columns( :id = :id, :Part = :Part ),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 1, 0 ),
	Preserve main table order( 1 )
);

Close( dt2, nosave );

dtJoin &amp;lt;&amp;lt; New Column( "Value2",
	Numeric,
	"Continuous",
	Format( "Percent", 10, 4 ),
	Formula( (:Value1 - :divisor) / :divisor )
);

dtJoin:Value2 &amp;lt;&amp;lt; delete property( "formula" );
dtJoin &amp;lt;&amp;lt; delete columns( "divisor" );
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jun 2019 04:07:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212274#M42491</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-06-07T04:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Percentage difference for a big amount of data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212275#M42492</link>
      <description>&lt;P&gt;Hi Jim!&lt;BR /&gt;Thank you so much for the help.&amp;nbsp;&lt;BR /&gt;I'm wondering if there is a way&amp;nbsp;&lt;BR /&gt;1) to Replace the Value2 (results) in the Column Value 1 initial cells.&lt;BR /&gt;2) if there are actually more columns ( like 30)&amp;nbsp; that I would need to do this operation(percentage difference),&lt;BR /&gt;do I need to hardcode code every new column, or is there a way I could multiply or for loop the columns creation.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 06:19:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212275#M42492</guid>
      <dc:creator>Jax</dc:creator>
      <dc:date>2019-06-07T06:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Percentage difference for a big amount of data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212311#M42499</link>
      <description>&lt;P&gt;The Value 2 results can easily replace the Value 1 results.&lt;/P&gt;
&lt;P&gt;No you do not need to hard code the JSL for all of the columns.&amp;nbsp; I have expanded my previous code to illistrate how to run this on as many columns as there are in the data table.&amp;nbsp; I also made the assumptions that you would not want the original Value1 data changed for the Time=0 rows, but if that is not the case, then just remove the If() statement that is making that decision&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

// Create a subset with only the data where Time = 0
dt2 = dt &amp;lt;&amp;lt; subset( Rows( dt &amp;lt;&amp;lt; get rows where( :Time == 0 ) ), selected columns( 0 ) );

// Delete the Time column.  In the join step below, it
// will write on top of the original Time column if
// it remains in the subsetted data table
dt2 &amp;lt;&amp;lt; delete columns( "Time" );

// Create a list of the column names so all of them can be 
// changed to a new name for the Join below.  Eliminate
// the columns "id" and "Part" from the name change since
// they will be used in the column matching in the Join.
divisorColNames = dt2 &amp;lt;&amp;lt; get column names( string );
For( i = N Items( divisorColNames ), i &amp;gt;= 1, i--,
	If( divisorColNames[i] == "id" | divisorColNames[i] == "Part",
		divisorColNames = Remove( divisorColNames, i, 1 )
	)
);

// Rename all of the divisor columns by "adding divisor_"
// in front of each name
For( i = 1, i &amp;lt;= N Items( divisorColNames ), i++,
	Column( dt2, divisorColNames[i] ) &amp;lt;&amp;lt; set name(
		"divisor_" || Char( Column( dt2, divisorColNames[i] ) &amp;lt;&amp;lt; get name )
	)
);

// Join the data tables.  All of the matching id and part
// values will be joined to all rows with the same values
dtJoin = dt &amp;lt;&amp;lt; Join(
	With( dt2 ),
	Merge Same Name Columns,
	Match Flag( 0 ),
	By Matching Columns( :id = :id, :Part = :Part ),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 1, 0 ),
	Preserve main table order( 1 )
);

// The dt2 data table is no longer needed so close it
Close( dt2, nosave );

// Loop through all of the columns and create the new values
// unless the Time value is 0
For( theCol = 1, theCol &amp;lt;= N Items( divisorColNames ), theCol++,
	For( theRow = 1, theRow &amp;lt;= N Rows( dtJoin ), theRow++,
		If( dtJoin:Time[theRow] != 0,
			Column( dtJoin, divisorColNames[theCol] )[theRow] = (
			Column( dtJoin, divisorColNames[theCol] )[theRow]
			-Column( dtJoin, "divisor_" || divisorColNames[theCol] )[theRow]) /
			Column( dtJoin, "divisor_" || divisorColNames[theCol] )[theRow]
		)
	)
);

// Delete all of the no longer needed divisor columns
For( i = 1, i &amp;lt;= N Items( divisorColNames ), i++,
	dtJoin &amp;lt;&amp;lt; delete columns( "divisor_" || divisorColNames[i] )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jun 2019 11:18:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/212311#M42499</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-06-07T11:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Percentage difference for a big amount of data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/213660#M42739</link>
      <description>Thank you so much Jim !</description>
      <pubDate>Wed, 19 Jun 2019 08:44:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-Percentage-difference-for-a-big-amount-of-data/m-p/213660#M42739</guid>
      <dc:creator>Jax</dc:creator>
      <dc:date>2019-06-19T08:44:43Z</dc:date>
    </item>
  </channel>
</rss>

