<?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 I want to add formula to subtract 1st and 4th row, then 2nd and 5th row.. then 3rd and 6th row and so on..urgent please help! in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535603#M75791</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;:RESULT is the column where I want to subtract row 1 and row 4, then row 2 and row 5 and so on until all the rows finishes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;:TEST is currently an empty column where I want to store the results of :RESULT column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following script in the formula but it doesn't work? Not sure why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:RESULT &amp;lt;&amp;lt; Data Type( Numeric );
:TEST &amp;lt;&amp;lt; Data Type( Numeric );
For( i = 1, i &amp;lt;= N Rows(), i++,
	Abs( :RESULT[i] - :RESULT[i + 3] )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 17:08:08 GMT</pubDate>
    <dc:creator>LearningJMP</dc:creator>
    <dc:date>2023-06-09T17:08:08Z</dc:date>
    <item>
      <title>I want to add formula to subtract 1st and 4th row, then 2nd and 5th row.. then 3rd and 6th row and so on..urgent please help!</title>
      <link>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535603#M75791</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;:RESULT is the column where I want to subtract row 1 and row 4, then row 2 and row 5 and so on until all the rows finishes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;:TEST is currently an empty column where I want to store the results of :RESULT column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following script in the formula but it doesn't work? Not sure why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:RESULT &amp;lt;&amp;lt; Data Type( Numeric );
:TEST &amp;lt;&amp;lt; Data Type( Numeric );
For( i = 1, i &amp;lt;= N Rows(), i++,
	Abs( :RESULT[i] - :RESULT[i + 3] )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:08:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535603#M75791</guid>
      <dc:creator>LearningJMP</dc:creator>
      <dc:date>2023-06-09T17:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: I want to add formula to subtract 1st and 4th row, then 2nd and 5th row.. then 3rd and 6th row and so on..urgent please help!</title>
      <link>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535616#M75792</link>
      <description>&lt;P&gt;Figured it out:&lt;/P&gt;
&lt;P&gt;Had to update line:&amp;nbsp;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Abs( :RESULT[i] - :RESULT[i + 3] )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;to&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:TEST[i]=Abs( :RESULT[i] - :RESULT[i + 3] )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Aug 2022 19:13:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535616#M75792</guid>
      <dc:creator>LearningJMP</dc:creator>
      <dc:date>2022-08-19T19:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: I want to add formula to subtract 1st and 4th row, then 2nd and 5th row.. then 3rd and 6th row and so on..urgent please help!</title>
      <link>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535630#M75793</link>
      <description>&lt;P&gt;Your formula should not contain a For() loop, unless you are running this not as a JMP formula, but rather as JSL in open code.&amp;nbsp; If you specify the code as being a formula for the column, JMP automatically loops through each row of the data, and applies the formula.&amp;nbsp; Thus, the For() loop is not required&amp;nbsp; Below is a little script that creates a new column and then adds a formula for the column.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
dt &amp;lt;&amp;lt; New Column( "The New Column",
	formula( If( :ATT1 == 0, 0, Abs( :RESULT - :RESULT[Row() + 3] ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have an empty column(for example, called "mytest") you can use a For Each Row() function to loop through the data table and calculate values&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
For Each Row(
	If( :ATT1 == 0,
		:mytest = 0,
		:mytest = Abs( :RESULT - :RESULT[Row() + 3] )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, as you have indicated, you can use a For() loop to loop through the data table.&amp;nbsp; This code requires that one specifies the specific row to operate on&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
For( i=1, i&amp;lt;=N Rows(dt), i++,
	If( :ATT1[i] == 0,
		:mytest[i] = 0,
		:mytest[i] = Abs( :RESULT[i] - :RESULT[i + 3] )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Aug 2022 19:11:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535630#M75793</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-08-19T19:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: I want to add formula to subtract 1st and 4th row, then 2nd and 5th row.. then 3rd and 6th row and so on..urgent please help!</title>
      <link>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535854#M75810</link>
      <description>&lt;P&gt;In addition, to calculate with different rows, I recommend the function lag, that returns the value of a row relative to current row, and you do not need a loop.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Georg_0-1661149237497.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/44900iCB6AFA27CE81902B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Georg_0-1661149237497.png" alt="Georg_0-1661149237497.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 06:20:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535854#M75810</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2022-08-22T06:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: I want to add formula to subtract 1st and 4th row, then 2nd and 5th row.. then 3rd and 6th row and so on..urgent please help!</title>
      <link>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535857#M75812</link>
      <description>&lt;P&gt;Besides using Lag to calculate there is also specific row function for this: Dif ( &lt;A href="https://www.jmp.com/support/help/en/16.2/#page/jmp/row-functions-2.shtml?os=win&amp;amp;source=application#ww4976282" target="_self"&gt; JSL Syntax Reference &amp;gt; JSL Functions &amp;gt; Row Functions - Dif(col, n)&lt;/A&gt; ). Sometimes it might work better than using Lag.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 07:33:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/I-want-to-add-formula-to-subtract-1st-and-4th-row-then-2nd-and/m-p/535857#M75812</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-08-22T07:33:55Z</dc:date>
    </item>
  </channel>
</rss>

