<?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: Looking to generate two columns based on some pattern from other columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447337#M69418</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;, thanks for your response.&lt;BR /&gt;&lt;BR /&gt;I am not able to get the correct (updated requirement) start point. In the Data Table ("Sample Data Updated") and image, I had entered corrected data columns&amp;nbsp; manually.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The formula. I used to get "Required Column 1 Old" and " Required Column 2 Old" is this (It is just like you give me, I added occurrence condition on it) -&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;RCValue = "";
:Required Column 1[Row()] = .;
If( :Occurrence != Lag( Occurrence, -1 ),
	other = "Yes"
);
If( Row() == 1 | :ID != Lag( :ID ) | :"Sub-set"n != Lag( :"Sub-set"n ),
	counter = 0;
	withinStart = "No";
	other = "Yes";
);
If(
	:Sensor == "Primary" &amp;amp; :Occurrence == Lag( :Occurrence, -1 ) &amp;amp; Dif( :Occurrence ) == 0 &amp;amp;
	withinStart == "Yes",
		RCValue = "End";
		withinStart = "No";
		other = "No";,
	:Occurrence != Lag( Occurrence, -1 ) &amp;amp; Lag( :Sensor, -1 ) != "Primary" &amp;amp; withinStart == "No"
	 &amp;amp; other == "Yes" &amp;amp; Row() != N Rows( Current Data Table() ),
		withinStart = "Yes";
		counter = counter + 1;
		RCValue = "Start";
);
If( withinStart == "Yes" | RCValue == "End",
	:Required Column 1[Row()] = counter
);
RCValue;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_0-1640088826157.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38571i6C0801DAA101B8EB/image-size/large?v=v2&amp;amp;px=999" role="button" title="HSS_0-1640088826157.png" alt="HSS_0-1640088826157.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Dec 2021 14:20:11 GMT</pubDate>
    <dc:creator>HSS</dc:creator>
    <dc:date>2021-12-21T14:20:11Z</dc:date>
    <item>
      <title>Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/445881#M69366</link>
      <description>&lt;P&gt;Hi All,&lt;BR /&gt;&lt;BR /&gt;I am looking to generate two new columns based on patterns in other two columns ( "Required column1" and "Required Column2"). Please see the attached image -&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_1-1639688163428.png" style="width: 927px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38490iDD44C39F10D277BF/image-dimensions/927x633?v=v2" width="927" height="633" role="button" title="HSS_1-1639688163428.png" alt="HSS_1-1639688163428.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help/suggestion ?&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:07:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/445881#M69366</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2023-06-09T18:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/445984#M69368</link>
      <description>&lt;P&gt;Here is a formula for the column you refer to Required Column 2.&amp;nbsp; When you study the code, you will see that all it is doing is applying the logic rules you have stated that need to be checked when determining the Start and End values.&amp;nbsp; It also contains the setting of the value for the column Required Column 1.&amp;nbsp; To run this formula, simply create the Required Column 1 and Required Column 2.&amp;nbsp; Set Required Column 2 to be a character column.&amp;nbsp; Then open the formula for Required Column 2 and copy the formula below into the column.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1639694637149.png" style="width: 581px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38492i8814AC1A2235446D/image-dimensions/581x523?v=v2" width="581" height="523" role="button" title="txnelson_0-1639694637149.png" alt="txnelson_0-1639694637149.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;RCValue = "";
:Required Column 1[Row()] = .;
If( :Sensor != "Primary",
	other = "Yes"
);
If( Row() == 1 | :ID != Lag( :ID ) | :"Sub-set"n != Lag( :"Sub-set"n ),
	counter = 0;
	withinStart = "No";
	other = "Yes";
);
If(
	:Sensor == "Primary" &amp;amp; withinStart == "Yes",
		RCValue = "End";
		withinStart = "No";
		other = "No";,
	:Sensor == "Primary" &amp;amp; Lag( :Sensor, -1 ) != "Primary" &amp;amp; withinStart == "No" &amp;amp; other == "Yes" &amp;amp; Row() !=
	N Rows( Current Data Table() ),
		withinStart = "Yes";
		counter = counter + 1;
		RCValue = "Start";
);
If( withinStart == "Yes" | RCValue == "End",
	:Required Column 1[Row()] = counter
);
RCValue;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 22:46:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/445984#M69368</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-12-16T22:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/446012#M69369</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It almost worked with few false entries. I believe we must add extra condition on :Occurrence column. That is :Occurrence must change to set :Required Column 2 == "Start" (and may be option - it should be same when :Required Column 2 == "End").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like - Dif(:Occurrence) !=0 then only&amp;nbsp; :Required Column 2 == "Start"&lt;BR /&gt;&lt;BR /&gt;For my sample data (95 rows) was fine with your formula but my actual data which has more than 300k rows, it is giving many wrong entries like below - (I think it should be fine once additional requirement on :Occurrence will be added.) This is just one off screenshot of the wrong entry.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_0-1639707466272.png" style="width: 663px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38495iD3293226647B4214/image-dimensions/663x320?v=v2" width="663" height="320" role="button" title="HSS_0-1639707466272.png" alt="HSS_0-1639707466272.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Hopefully!!&amp;nbsp; I can modify the formula/code and can add requirement of :Occurrence. on top of your formula.&lt;BR /&gt;&lt;BR /&gt;Thanks again for your support.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 02:21:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/446012#M69369</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-17T02:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447250#M69408</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;and All,&lt;BR /&gt;&lt;BR /&gt;I was able to modify your code based perfectly for my requirement. But on the 2nd stage troubleshooting I need something like this --&lt;BR /&gt;&lt;BR /&gt;Mark :Sensor = "Primary" (1st) around consecutive change in :Occurrence.&amp;nbsp; &amp;nbsp; In the given screenshot -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;required values in between&lt;STRONG&gt; ---&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;Last "Primary"&lt;/STRONG&gt; in &lt;STRONG&gt;Occurrence = 2&lt;/STRONG&gt;&amp;nbsp; and&amp;nbsp; &lt;STRONG&gt;First "Primary"&lt;/STRONG&gt; in &lt;STRONG&gt;Occurrence = 3&amp;nbsp; &lt;/STRONG&gt;[consecutive change in Occurrence]&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Finding first Primary is not that difficult, not sure how to find last primary ? Thinking to somehow invert (descending order) the subset data for Occurrence = 2, find the value and then revert it back. Not able to put in a formula!! Any other way to do that ?&lt;BR /&gt;&lt;BR /&gt;Any help?&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_0-1640075781746.png" style="width: 458px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38566i55EB99DA4E4B241D/image-dimensions/458x368?v=v2" width="458" height="368" role="button" title="HSS_0-1640075781746.png" alt="HSS_0-1640075781746.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 08:43:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447250#M69408</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-21T08:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447314#M69416</link>
      <description>&lt;P&gt;You have modified the code I previously provided to get the results that you provide in your most recent response. Please provide the JSL you are using to get the results you are showing in your sample data table.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 10:58:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447314#M69416</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-12-21T10:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447337#M69418</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;, thanks for your response.&lt;BR /&gt;&lt;BR /&gt;I am not able to get the correct (updated requirement) start point. In the Data Table ("Sample Data Updated") and image, I had entered corrected data columns&amp;nbsp; manually.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The formula. I used to get "Required Column 1 Old" and " Required Column 2 Old" is this (It is just like you give me, I added occurrence condition on it) -&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;RCValue = "";
:Required Column 1[Row()] = .;
If( :Occurrence != Lag( Occurrence, -1 ),
	other = "Yes"
);
If( Row() == 1 | :ID != Lag( :ID ) | :"Sub-set"n != Lag( :"Sub-set"n ),
	counter = 0;
	withinStart = "No";
	other = "Yes";
);
If(
	:Sensor == "Primary" &amp;amp; :Occurrence == Lag( :Occurrence, -1 ) &amp;amp; Dif( :Occurrence ) == 0 &amp;amp;
	withinStart == "Yes",
		RCValue = "End";
		withinStart = "No";
		other = "No";,
	:Occurrence != Lag( Occurrence, -1 ) &amp;amp; Lag( :Sensor, -1 ) != "Primary" &amp;amp; withinStart == "No"
	 &amp;amp; other == "Yes" &amp;amp; Row() != N Rows( Current Data Table() ),
		withinStart = "Yes";
		counter = counter + 1;
		RCValue = "Start";
);
If( withinStart == "Yes" | RCValue == "End",
	:Required Column 1[Row()] = counter
);
RCValue;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_0-1640088826157.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38571i6C0801DAA101B8EB/image-size/large?v=v2&amp;amp;px=999" role="button" title="HSS_0-1640088826157.png" alt="HSS_0-1640088826157.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 14:20:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447337#M69418</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-21T14:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447488#M69429</link>
      <description>&lt;P&gt;i am confused.&amp;nbsp; From what I can see, the script that I wrote seems to work, except that after line 44 in the data table, you have changed the rules, and now want the End to be on the row prior to the next value of Primary.&amp;nbsp; Which is 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-1640108529298.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38615iF1CD43965883B61C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1640108529298.png" alt="txnelson_0-1640108529298.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 17:43:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447488#M69429</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-12-21T17:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447521#M69431</link>
      <description>&lt;P&gt;Hi Jim,&lt;BR /&gt;&lt;BR /&gt;Sorry for the confusion.&lt;BR /&gt;&lt;BR /&gt;Your original formula (I believe, I have not messed it up) worked for most of the cases but also captured few wrong points and missed few on full set of data. In the attached subset of the data (only for one "ID" and&amp;nbsp;one&amp;nbsp; value of "Sub-set") there is a column based on your formula which has few wrong points.&lt;BR /&gt;&lt;BR /&gt;Rows:&amp;nbsp; 647-649 wrong entry (Red Colour)&lt;BR /&gt;Rows: 868-937 not captured (Red Colour)&lt;BR /&gt;Rows: 1307-1311 wrong entry (Red Colour)&lt;BR /&gt;&lt;BR /&gt;And this was fixed when I put condition on :Occurrence.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Now I am looking for -&lt;BR /&gt;&lt;BR /&gt;1. Last Primary Sensor in occurrence = n (say n = 2), mark it as "Start"&lt;BR /&gt;&lt;BR /&gt;2. First Primary Sensor in Occurrence = n+1 (= 3), and if there is no primary sensor for n = 3, it should stope/mark the value in Occurrence = n+2 == 4. Mark it as "End"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;3. And last fill the numbers between "Start" and "End" in a new column.&lt;BR /&gt;&lt;BR /&gt;Alternate way to think of (may be) --&lt;BR /&gt;If we can mark - in any single occurrence n (n = 2) First Primary Sensor as END and in last primary sensor as Start and then fill a values between Start and End in a new column.&lt;BR /&gt;&lt;BR /&gt;I hope this will help and make things clear.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;I think this can be, if I can find a&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 18:54:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447521#M69431</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-21T18:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447757#M69452</link>
      <description>&lt;P&gt;The issue appears to be with the logic being applied to the JSL variable "other".&amp;nbsp; I do not have time to work on the issue today, but tomorrow afternoon, I should be able to do some investigation.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 13:37:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447757#M69452</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-12-22T13:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447863#M69476</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;I did some progress - and identify correctly the start and end point of each set. I used a very simple logic, you can see in the formula column.&lt;BR /&gt;&lt;BR /&gt;But now I am struggling to put numbers between each pair of "Start" and "End" point. I getting issue in stopping the counter at "End". My issue might have the same complicacy but at least now I have clearing marking/tag on my start and end point.&lt;BR /&gt;&lt;BR /&gt;Any help with this ?&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_0-1640247234316.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38644i32CF7EB92ED9BE74/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HSS_0-1640247234316.png" alt="HSS_0-1640247234316.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 08:18:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447863#M69476</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-23T08:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447883#M69478</link>
      <description>&lt;P&gt;I gave a go with this. I try to avoid using Lag() whenever possible and replace it with Col functions. The most difficult formula seems to be &lt;EM&gt;Required Column 1&lt;/EM&gt; and I couldn't quickly figure out good formula without using Lag() (there is most likely a solution with Col Cumulative Sum somehow). One idea would be to fill places between Start and End with "Ongoing" or something similar, then you could maybe use Col Cumulative Sum easier, but then the most difficult formula would most likely just move to&amp;nbsp;&lt;EM&gt;Start and End&lt;/EM&gt;.&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Current Data Table();
//Numbering of Occurrence
dt &amp;lt;&amp;lt; New Column("NumberOfOcc", Numeric, Nominal, Formula(
	If(:Sensor == "Primary",
		Col Cumulative Sum(:Sensor == "Primary", :ID, :"Sub-set"n, :Occurrence),
		.
	);
));

//Start and End
dt &amp;lt;&amp;lt; New column("StartEnd", Character, Nominal, Formula(
	If(:NumberOfOcc == 1, 
		"End"
	, Col Max(:NumberOfOcc, :ID,:"Sub-set"n, :Occurrence) == :NumberOfOcc,
		"Start"
	, //else
		""
	)
));

//Required Column 1, this could most likely be made somehow with Col Cumulative Sum
dt &amp;lt;&amp;lt; New column("Req1", Numeric, Ordinal, Formula(
	If(Row() == 1,
		val = .
	);
	If(:StartEnd == "Start",
		val = 1
	, IsMissing(:StartEnd) | :StartEnd == "End",
		val += 1;
	);
	If(:Lag(:StartEnd) == "End" | (Row() == Col Max(Row()) &amp;amp; :StartEnd == "Start") | (:StartEnd == "Start" &amp;amp; Lag(:StartEnd, -1) == "End"), //more missing checks can be added here
		val = .,
		val;
	)
));

//Required Column 2
dt &amp;lt;&amp;lt; New column("Req2", Numeric, Nominal, Formula(
	If(!IsMissing(:Req1),
		Col Cumulative Sum(:StartEnd == "Start",
			:ID, :"Sub-set"n
		)
	,
		.
	)
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;If you have time, I would suggest testing both ways of solving this, the one &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt; has provided with more heavy use of Lag and comparisons, and the one I have with Col formulas. Both definitely have their use cases and understanding them will help you in a long run when writing formulas/calculations in JMP. And in some cases when you understand how to combine both, you can solve quite difficult tasks with just formulas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also after you get the logic working, I would most likely remove Formulas from the datatable (or replace Formula() with &amp;lt;&amp;lt; Set Each value in script), because this will most likely break if order is changed in datatable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 10:05:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447883#M69478</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-12-23T10:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447937#M69486</link>
      <description>&lt;P&gt;Dear &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt; (Jarmo) and Dear &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt; (Jim),&lt;BR /&gt;&lt;BR /&gt;I am really thankful for your support and kindness.&lt;BR /&gt;&lt;BR /&gt;I will certainly find one working way by either of these two methods and some combination of these two.&lt;BR /&gt;&lt;BR /&gt;Many thanks again to both of you.&lt;BR /&gt;Merry Christmas and Happy New Year. Enjoy your time.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Harry&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 19:40:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/447937#M69486</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-23T19:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/448082#M69496</link>
      <description>&lt;P&gt;Hi All,&lt;BR /&gt;&lt;BR /&gt;Have another query, actually two -&lt;BR /&gt;&lt;BR /&gt;1. What is the difference, If I add more than one condition in single "If" statement vs. Adding more than one "If" statement with single condition. See the attached image - . First case is not giving correct results while the 2nd one is working fine. Results can be seen in the attached sample data. I am having difficulty to understand the differences here.&lt;BR /&gt;&lt;BR /&gt;To me it seems for each row -&amp;nbsp; in first case, if condition is true, output is given. This ends the results.&lt;BR /&gt;While in 2nd case, it will run all 3 if statements sequentially, irrespective of results of previous one and out put will be based on the last true condition. I am not sure if I am able to explain it correctly. Again, I guess in 2nd case (multiple if statement), there is a sort of overwrite on the previous If statement !&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HSS_0-1640604998632.png" style="width: 712px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38659i3AD03CD8B276E769/image-dimensions/712x445?v=v2" width="712" height="445" role="button" title="HSS_0-1640604998632.png" alt="HSS_0-1640604998632.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2.&amp;nbsp; There is a condition used in the above formula --&amp;nbsp; "&amp;nbsp; &amp;nbsp;Row() == Col Max(Row()) &amp;amp; :StartEnd == "Start"&amp;nbsp; &amp;nbsp;"&amp;nbsp; &amp;nbsp;How is it working? It works well, means - it is well written. But I am not able to visualize how the variable/counter "val" stops ?&lt;BR /&gt;&lt;BR /&gt;Any help with it ?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Dec 2021 11:49:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/448082#M69496</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-27T11:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/448181#M69499</link>
      <description>&lt;P&gt;1. Maybe this image gives explanation why the first idea won't work (if I remember correctly the second solution relies on that if you calculate&amp;nbsp; &lt;STRONG&gt;. + 1&lt;/STRONG&gt; it will be &lt;STRONG&gt;.&lt;/STRONG&gt;:(&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1640633086678.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38666i392AC41C78DB1C1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1640633086678.png" alt="jthi_2-1640633086678.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I did take the different comparisons from the If statement and just create formulas out of them so it is easier to see what returns True and when.&lt;/P&gt;&lt;P&gt;You could most likely get the first solution working by modifying the comparisons a bit (&lt;EM&gt; Is Missing(:StartEnd) &lt;STRONG&gt;&amp;amp; Lag(:StartEnd) != "End"&lt;/STRONG&gt; | :StartEnd == "End", val += 1&lt;/EM&gt;). But with this change you will have to make small change to second comparison also (add Row() != Col Max(Row()) check).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Idea for &lt;EM&gt;Row() == Col Max(Row()) &amp;amp; :StartEnd == "Start"&lt;/EM&gt; is just to to check if we are on last row of the table and :StartEnd value is "Start" we won't set the value as 1 based on previous if statement. Row() will tell you row number and Col Max(Row()) will return you maximum row number in the datatable. Might be a bit unnecessary check because it is last row of table (like the one after it with Start/End), but as it was in the results column, I did implement them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The general idea with the last if-else was following:&lt;/P&gt;&lt;P&gt;1. Lag(:StartEnd) == "End" -&amp;gt; this is general "stop" after End is countered&lt;/P&gt;&lt;P&gt;2. Row() == Col Max(Row()) &amp;amp; :StartEnd == "Start" -&amp;gt; to prevent returning 1 on last row if it is Start&lt;/P&gt;&lt;P&gt;3. :StartEnd == "Start" &amp;amp; Lag(:StartEnd, -1) == "End" -&amp;gt; to prevent returning 1 and 2 if there are no rows between Start and End&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use just one if with multiple comparisons by moving some of the comparisons around a bit (this seemed to return same result as Req1):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(
	Row() == 1, val = .,
	Row() != Col Max(Row()) &amp;amp; :StartEnd == "Start" &amp;amp; Lag(:StartEnd, -1) != "End", val = 1,
	Is Missing(:StartEnd) &amp;amp; Lag(:StartEnd) != "End" | :StartEnd == "End", val += 1,
	val =.
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully the explanation isn't too messy&lt;/P&gt;</description>
      <pubDate>Mon, 27 Dec 2021 19:37:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/448181#M69499</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-12-27T19:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Looking to generate two columns based on some pattern from other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/448204#M69501</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;for nice explanation.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Dec 2021 05:12:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-to-generate-two-columns-based-on-some-pattern-from-other/m-p/448204#M69501</guid>
      <dc:creator>HSS</dc:creator>
      <dc:date>2021-12-28T05:12:34Z</dc:date>
    </item>
  </channel>
</rss>

