<?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 define a new column based on n consecutive rows condition in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/498126#M73466</link>
    <description>&lt;P&gt;Thanks Jarmo,&lt;BR /&gt;&lt;BR /&gt;It is working perfectly. Now I have to integrate this in my script. I hope I can do that.&lt;BR /&gt;thanks, HSS&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 02:25:25 GMT</pubDate>
    <dc:creator>HSS</dc:creator>
    <dc:date>2022-06-02T02:25:25Z</dc:date>
    <item>
      <title>How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/496883#M73442</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am looking for formula column where its elements depends upon the&amp;nbsp; at least 10 consecutive rows of other column full filling a threshold value. Please see the attached image and data. Those also include the required column "Correct failer region".&lt;BR /&gt;Any help please.&lt;BR /&gt;Thanks, HSS&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_2-1654078295741.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/42839i63B513A2AB52F4CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HSS_2-1654078295741.png" alt="HSS_2-1654078295741.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:00:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/496883#M73442</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2023-06-09T17:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/496916#M73443</link>
      <description>&lt;P&gt;&lt;LI-MESSAGE title="Data table subscripting" uid="21013" url="https://community.jmp.com/t5/Uncharted/Data-table-subscripting/m-p/21013#U21013" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; is one option. &lt;/P&gt;
&lt;P&gt;I changed Current column name:&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("a", Numeric, Ordinal,
	&amp;lt;&amp;lt; Set Each Value(
		If(Row() == 1,
			val = 1; // this is breaking rule of &amp;gt; 750, so we define it separately
			change = 1;
		);

		next_vals = :Current[Row()::Min(Dim()[1], Row() + 9)];
		over_limit = Sum(next_vals &amp;gt;= 750);

		If(change &amp;amp; over_limit &amp;gt;= 10,
			val++;
			change = 0;
		, over_limit &amp;lt; 10,
			change = 1;
		);

		val;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jun 2022 11:18:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/496916#M73443</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-01T11:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/498126#M73466</link>
      <description>&lt;P&gt;Thanks Jarmo,&lt;BR /&gt;&lt;BR /&gt;It is working perfectly. Now I have to integrate this in my script. I hope I can do that.&lt;BR /&gt;thanks, HSS&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 02:25:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/498126#M73466</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2022-06-02T02:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/502521#M73574</link>
      <description>&lt;P&gt;Hi Jarmo and all,&lt;BR /&gt;&lt;BR /&gt;This code is working fine and I am able to implement it in script perfectly fine.&lt;BR /&gt;&lt;BR /&gt;But on the other hand, I am not able to understand it. I want to modify it a bit but not able to do that. Would you please help me in that -&lt;BR /&gt;1. What is this statement is doing -&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;next_vals = :Current[Row()::Min(Dim()[1], Row() + 9)];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2. I am not able to understand where the increment on 'change' is taking place and how this conditional can be satisfied ?&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;If(change &amp;amp; over_limit &amp;gt;= 10,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I believe it is same as - "If( change &amp;gt;=10 &amp;amp; over_limit &amp;gt;=10&lt;/P&gt;&lt;P&gt;3. In my current problem, I would like to increase the counter by one once the desired region is finished (with minimum 10 entries) -- something like this -&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_1-1654676858263.png" style="width: 565px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/43080iF4F290BE14E2AC24/image-dimensions/565x518?v=v2" width="565" height="518" role="button" title="HSS_1-1654676858263.png" alt="HSS_1-1654676858263.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any help ?&lt;/P&gt;&lt;P&gt;thanks, HSS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 08:28:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/502521#M73574</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2022-06-08T08:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/502524#M73575</link>
      <description>&lt;P&gt;There is a mistake in the attached image in previous message. Please ignore the last red rectangle, as by mistake, I have change the counter for old requirement too. That should not be the case.&amp;nbsp;&lt;BR /&gt;thanks, HSS&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 08:31:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/502524#M73575</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2022-06-08T08:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/502975#M73589</link>
      <description>&lt;P&gt;What I would suggest doing is modifying the script to something like this which will allow you to run it "row by row":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Names Default To Here(1);
// Clear Log();
dt = Current Data Table();
run_script = Expr(
	If(Row() == 1,
		val = 1; // this is breaking rule of &amp;gt; 750, so we define it separately
		change = 1;
	);

	next_vals = :Current[Row()::Min(Dim()[1], Row() + 9)];
	over_limit = Sum(next_vals &amp;gt;= 750);

	If(change &amp;amp; over_limit &amp;gt;= 10,
		val++;
		change = 0;
	, over_limit &amp;lt; 10,
		change = 1;
	);
	val;
	show(row(), val, change, next_vals, over_limit);
	Write("\!N");
);

Row() = 1;
run_script;
Row() = 2;
run_script;
Row() = 5;
run_script;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can fairly easily run the script in parts and look at the log to see what happens (you can also run one row at the time if you want to).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Script Window and Embedded Log:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1654700536440.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/43094i6B654634E9F1CA5A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1654700536440.png" alt="jthi_1-1654700536440.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Scripting Index is also helpful in explaining the functions, such as Dim().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this won't be enough of a help, please comment in this post and tag me, I can try to explain it in more detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 15:03:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/502975#M73589</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-08T15:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503073#M73594</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;Thanks for explanation.&lt;BR /&gt;&lt;BR /&gt;I run it row by row and got a quite a bit.&lt;BR /&gt;&lt;BR /&gt;Still I have no clue why do we have variable 'change' in the script and what is its purpose ? It is just taking two value, either 1 (as the set value) and 0 whenever we are getting more than 10 entries in a row with satisfying current value. But it does not appear anywhere in new column indexing. But if I am running it without variable 'Change' I do not get correct entries. But I am not able to figure out how and where does it impact our calculation/indexing.&lt;BR /&gt;&lt;BR /&gt;and 3rd part of the problem - how can I increase the running index when the desired region of :current&amp;gt;=750 ends ?&lt;BR /&gt;&lt;BR /&gt;thanks, HSS&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 15:57:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503073#M73594</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2022-06-08T15:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503283#M73597</link>
      <description>&lt;P&gt;Change is used to increase val if needed. For problem three, it would require some re-writing on the algorithm as the conditions have changed&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 17:06:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503283#M73597</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-08T17:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503732#M73608</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;I tried something on my new requirement. It may not be the best solution but it is a work around. And it is very close to the solution you suggested for original problem. Till now it is working fine.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1, val = 1 );
Next_10_values = Sum( :Current[Index( Row(), Min( Dim()[1], Row() + 9 ) )] &amp;gt;= 750 );
Previous_10_values = Sum( :Current[Index( Row(), Min( Dim()[1], Row() - 9 ) )] &amp;gt;= 750 );
If(
	Next_10_values == 10 &amp;amp; Lag( :Current ) &amp;lt; 750 | Previous_10_values == 9 &amp;amp; :Current &amp;lt; 750 &amp;amp;
	Lag( :Current ) &amp;gt;= 750,
	val = val + 1
);
val;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Many thanks for your support.&lt;BR /&gt;Regards, HSS&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 03:07:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503732#M73608</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2022-06-09T03:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a new column based on n consecutive rows condition</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503778#M73609</link>
      <description>&lt;P&gt;I would maybe split the algorithm into three parts:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Increase counter when there is enough values over 750 (possibly set some support variable(s))&lt;/LI&gt;
&lt;LI&gt;Increase counter when there is even one value below 750 AFTER and do this only ONCE for each step 1. increase&amp;nbsp;(possibly set some support variable(s))&lt;/LI&gt;
&lt;LI&gt;Don't increase counter&amp;nbsp;(possibly set some support variable(s))&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;this might be easiest (maybe not easiest, but most clear) to do with some additional support variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() == 1,
	counter = 1;
	allow_over_limit_change = 1;
	allow_below_limit_change = 0;
);

current_vals_to_check = :Current[Row()::Min(Dim()[1], Row() + 9)];
over_limit_count = Sum(current_vals_to_check &amp;gt;= 750);

If(allow_over_limit_change &amp;amp; over_limit_count &amp;gt;= 10,
	counter++;
	allow_below_limit_change = 1;
	allow_over_limit_change = 0;
, allow_below_limit_change &amp;amp; :Current &amp;lt; 750,
	counter++;
	allow_below_limit_change = 0;
	allow_over_limit_change = 1;
);
counter;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Row() == 1 if statement can most likely be replaced with this (in my opinion not as clear as using If statement)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;As Constant(counter = 1);
As Constant(allow_over_limit_change = 1);
As Constant(allow_below_limit_change = 0);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2022 05:59:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-new-column-based-on-n-consecutive-rows-condition/m-p/503778#M73609</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-09T05:59:12Z</dc:date>
    </item>
  </channel>
</rss>

