<?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 directly calculate the number of consecutive conditions? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275264#M53405</link>
    <description>&lt;P&gt;Looks like second If had a single = for assignment instead of a == for equivalence test.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;If( Row() == 1,
    hCounter = 0,
    If(
        Lag( :name ) == :name,
            If( :age &amp;gt; Lag( :age, 1 ),
                Empty()
            ),
        hCounter++, hCounter = 0
    )
);
If( hCounter == 0,
    .,
    hCounter
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 17:06:05 GMT</pubDate>
    <dc:creator>johnmoore</dc:creator>
    <dc:date>2020-06-24T17:06:05Z</dc:date>
    <item>
      <title>How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/234122#M46424</link>
      <description>&lt;P&gt;For example, take "height" as an example and count the consecutive number of "height"s in the row greater than the "height" in the previous row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added an auxiliary column h to determine whether the "height" of the row is greater than the "height" of the previous row, and then counted the consecutive "height" of the row greater than the "height" of the previous row in the other column.If the "height" is less than the "height" of the previous row&amp;nbsp; have to recalculate.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2019-11-18_20-23.png" style="width: 693px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/20353iD8EE7F7F1749ADB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2019-11-18_20-23.png" alt="2019-11-18_20-23.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P class="src"&gt;How can do this calculation in one step?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class="src"&gt;I tried this, but it didn't work:&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if(:height&amp;gt;Lag(:height,1),row()-Contains(:height[Index(1,Row())],:height&amp;lt;Lag(:height,1),-1))&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;Thanks!&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 18 Nov 2019 12:30:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/234122#M46424</guid>
      <dc:creator>lwx228</dc:creator>
      <dc:date>2019-11-18T12:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/234135#M46427</link>
      <description>&lt;P&gt;The problem has a fairly simple solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	hCounter = 0,
	If( :height &amp;gt; Lag( :height, 1 ),
		hCounter++,
		hCounter = 0
	)
);
If( hCounter == 0,
	.,
	hCounter
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This version will produce missing values when there are 0 lags that meet the condition, just like your 2 column solution.&amp;nbsp; If you want the resulting value to be a zero and not a missing value, just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	hCounter = 0,
	If( :height &amp;gt; Lag( :height, 1 ),
		hCounter++,
		hCounter = 0
	)
);

hCounter;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a complete comparison of the 2 methods&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt &amp;lt;&amp;lt; New Column( "h",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula( If( Row() == 1, 0, :height &amp;gt; Lag( :height, 1 ) ) )
);
	
dt &amp;lt;&amp;lt; New Column( "Two Columns Used",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula( If( :h == 1, Row() - Contains( :h[Index( 1, Row() )], 0, -1 ) ) )
);
dt &amp;lt;&amp;lt; New Column( "All in one",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula(
		If( Row() == 1,
			hCounter = 0,
			If( :height &amp;gt; Lag( :height, 1 ),
				hCounter++,
				hCounter = 0
			)
		);
		If( hCounter == 0,
			.,
			hCounter
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2019 13:20:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/234135#M46427</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-11-18T13:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/234139#M46430</link>
      <description>Looping is a good idea here!&lt;BR /&gt;&lt;BR /&gt;Thank Jim!</description>
      <pubDate>Mon, 18 Nov 2019 14:16:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/234139#M46430</guid>
      <dc:creator>lwx228</dc:creator>
      <dc:date>2019-11-18T14:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274481#M53235</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a similar challenge.&amp;nbsp; However, I need to calculate the number of sequential (incremented by 1) values in a column.&amp;nbsp; I attach the BigClass example to illustrate.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Onjai_0-1592581884644.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24720i7E8E354322714312/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Onjai_0-1592581884644.png" alt="Onjai_0-1592581884644.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I used your formula to calculate column :h based on :age, but desire a formula that will start at the 1st value of a sequence and grouped by :name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be achieved with a formula?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Onjai&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 15:55:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274481#M53235</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-19T15:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274482#M53236</link>
      <description>&lt;P&gt;Just add an IF() statement in the formula that checks to see if the Lag(:Name) != :Name, and if not, then set your counter back to the starting point.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 16:05:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274482#M53236</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-06-19T16:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274496#M53237</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;Not quite sure what I am doing wrong, but he If statement is trowing this error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Onjai_0-1592584328074.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24721i4987BD8350709C7F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Onjai_0-1592584328074.png" alt="Onjai_0-1592584328074.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
    hCounter = 0,
    If(
        Lag( :name ) = :name,
            If( :age &amp;gt; Lag( :age, 1 ),
                Empty()
            ),
        hCounter++, hCounter = 0
    )
);
If( hCounter == 0,
    .,
    hCounter
);&lt;/CODE&gt;&lt;/PRE&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, 19 Jun 2020 16:45:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274496#M53237</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-19T16:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274523#M53241</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Found the error, but the formula still does not calculate column 10 as desired.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alice's height was measured for 5 consecutive years.&amp;nbsp; I need a column to show which rows are consecutive.&amp;nbsp; Clay only had 2 consecutive years of height measurement.&amp;nbsp; Carol had 3 consecutive years of height measurements but Column 10 shows 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Onjai_0-1592593724492.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24724i553153441001E6F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Onjai_0-1592593724492.png" alt="Onjai_0-1592593724492.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Formula in Column 10:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
    hCounter = 0,
    If( Lag( :name ) == :name,
        If( :age &amp;gt; Lag( :age, 1 ),
            hCounter
            ++),
        hCounter = 0
    )
);
If( hCounter == 0,
    .,
    hCounter
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 19:55:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274523#M53241</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-19T19:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274533#M53243</link>
      <description>&lt;P&gt;I don't understand the rule for the column "desired by :name".&amp;nbsp; You have one missing value at the end of the rows for Alice, but 2 rows with missing values for Carol and Chris, and then back to only 1 row of missing values for Clay.&amp;nbsp; I do not understand&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:15:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274533#M53243</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-06-19T20:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274542#M53247</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;No problem.&amp;nbsp; I named the column to show what I was looking for as an end result of the formula.&lt;/P&gt;&lt;P&gt;Looking at the "desired by:name" column for Carol.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Height measurements were taken for 3 consecutive years (ages 14, 15, 16).&amp;nbsp; But the formula shows 4.&lt;/P&gt;&lt;P&gt;The difference in age, row to row, should be 1.&amp;nbsp; If it is anything &amp;lt;&amp;gt;1 then it should be empty.&lt;/P&gt;&lt;P&gt;I need the Lag to increment by 1 until the value is &amp;lt;&amp;gt;1.&amp;nbsp; Which should signal if a year in height measurement was missed.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Onjai_1-1592598287544.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24727i3318BC750722DD83/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Onjai_1-1592598287544.png" alt="Onjai_1-1592598287544.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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:29:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/274542#M53247</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-19T20:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275253#M53401</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am attaching a portion of my actual data set.&amp;nbsp; I am tracking the number of :rolls that are sequential by :master.&amp;nbsp; The formula is close, but I still need it to set the value of the first occurrence of the sequential roll if the difference is 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If( :master == Lag( :master ),&lt;BR /&gt;If( Dif( :roll, 1 ) == 1,&lt;BR /&gt;Dif( :roll, 1 ),&lt;BR /&gt;.&lt;BR /&gt;),&lt;BR /&gt;.&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I need to set the value of :sequential roll to 1 for row 8 &amp;amp; 11&amp;nbsp; because the difference = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Onjai_0-1593011789533.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24797i539576D7452269E3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Onjai_0-1593011789533.png" alt="Onjai_0-1593011789533.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 15:19:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275253#M53401</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-24T15:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275264#M53405</link>
      <description>&lt;P&gt;Looks like second If had a single = for assignment instead of a == for equivalence test.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;If( Row() == 1,
    hCounter = 0,
    If(
        Lag( :name ) == :name,
            If( :age &amp;gt; Lag( :age, 1 ),
                Empty()
            ),
        hCounter++, hCounter = 0
    )
);
If( hCounter == 0,
    .,
    hCounter
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 17:06:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275264#M53405</guid>
      <dc:creator>johnmoore</dc:creator>
      <dc:date>2020-06-24T17:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275271#M53409</link>
      <description>&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;I see the error but this does not provide the calculation and checks I require.&amp;nbsp; My last post shows a new data table and formula that is close.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Onjai&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 18:02:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275271#M53409</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-24T18:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to directly calculate the number of consecutive conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275291#M53420</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;It took me awhile but I eventually figured out how to add a value to the previous row if the condition was true.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to share this with you.&amp;nbsp; I am using this to tag sequential values within groups.&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If( Row() == 1,&lt;BR /&gt;.,&lt;BR /&gt;If( :master == Lag( :master ),&lt;BR /&gt;If( :roll - Lag( :roll ) == 1,&lt;BR /&gt;:seq. rolls v3[Row() - 1] = 1,&lt;BR /&gt;.&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 20:50:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-directly-calculate-the-number-of-consecutive-conditions/m-p/275291#M53420</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2020-06-24T20:50:27Z</dc:date>
    </item>
  </channel>
</rss>

