<?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 Increment a value for Run Number in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380107#M63032</link>
    <description>&lt;P&gt;I am trying to develop a formula that increments up the Run #. It should count up for each time a Shop Order has a new Process ID and reset back to 1 when a new Shop Order has not been run before. As shown below the Shop Order 532 has 3 different Process IDs, but they are not in order so it still increments up to 3 on the final one even though it isn’t in order. I created a column manually showing what I would want as an ideal outcome for the formula column. How would I write a formula to deal with this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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="dkraeuter_sunne_0-1619545627775.png" style="width: 646px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32366i1DFC81C32238B4D0/image-dimensions/646x411?v=v2" width="646" height="411" role="button" title="dkraeuter_sunne_0-1619545627775.png" alt="dkraeuter_sunne_0-1619545627775.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:29:18 GMT</pubDate>
    <dc:creator>dkraeuter_sunne</dc:creator>
    <dc:date>2023-06-10T23:29:18Z</dc:date>
    <item>
      <title>Increment a value for Run Number</title>
      <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380107#M63032</link>
      <description>&lt;P&gt;I am trying to develop a formula that increments up the Run #. It should count up for each time a Shop Order has a new Process ID and reset back to 1 when a new Shop Order has not been run before. As shown below the Shop Order 532 has 3 different Process IDs, but they are not in order so it still increments up to 3 on the final one even though it isn’t in order. I created a column manually showing what I would want as an ideal outcome for the formula column. How would I write a formula to deal with this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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="dkraeuter_sunne_0-1619545627775.png" style="width: 646px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32366i1DFC81C32238B4D0/image-dimensions/646x411?v=v2" width="646" height="411" role="button" title="dkraeuter_sunne_0-1619545627775.png" alt="dkraeuter_sunne_0-1619545627775.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:29:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380107#M63032</guid>
      <dc:creator>dkraeuter_sunne</dc:creator>
      <dc:date>2023-06-10T23:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Increment a value for Run Number</title>
      <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380154#M63039</link>
      <description>&lt;P&gt;Here is a formula you can use.&amp;nbsp; Create the new column Run #.&amp;nbsp; I suggest you make the modeling type "Ordinal".&amp;nbsp; Open the Formula Editor for the new column, and paste in the following.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	:Process ID &amp;lt;&amp;lt; set property( "Value Order", {Common Order( 0 ), Row Order Levels( 1 )} );
	Summarize( byGroup = by( :Process ID ) );
	:Process ID &amp;lt;&amp;lt; delete property("Value Order");
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Below is a script that will do the column creation and apply the formula for you&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( "Run #",
	ordinal,
	formula(
		If( Row() == 1,
			:Process ID &amp;lt;&amp;lt; set property( "Value Order", {Common Order( 0 ), Row Order Levels( 1 )} );
			Summarize( byGroup = by( :Process ID ) );
			:Process ID &amp;lt;&amp;lt; delete property("Value Order")
		);
		Contains( byGroup, :Process ID );
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Apr 2021 18:33:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380154#M63039</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-27T18:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Increment a value for Run Number</title>
      <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380219#M63051</link>
      <description>&lt;P&gt;Thank you for this. It doesn't quite do what I am looking for. See the mismatch between the "Ideal Outcome Column for Run #"&amp;nbsp;and the "Run #". The way the formula is currently working is just incrementing up no matter if a new SO is started.&amp;nbsp;&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="dkraeuter_sunne_0-1619550890491.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32369i55C7F602D85BB610/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dkraeuter_sunne_0-1619550890491.png" alt="dkraeuter_sunne_0-1619550890491.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 19:16:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380219#M63051</guid>
      <dc:creator>dkraeuter_sunne</dc:creator>
      <dc:date>2021-04-27T19:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Increment a value for Run Number</title>
      <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380252#M63058</link>
      <description>&lt;P&gt;Sorry, I missed the link with Shop Order.&amp;nbsp; That changes everything and makes the formula much simpler&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1 | :Shop Order != Lag( :Shop Order ),
	count = 1,
	If( :Process ID != Lag( :Process ID ),
		count
		++)
);
count;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:00:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380252#M63058</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-27T21:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Increment a value for Run Number</title>
      <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380280#M63061</link>
      <description>&lt;P&gt;That was closer, but it restarted the count for Shop Order # 532 at 1 the second time that it was listed since there was another Shop Order between runs 2 and 3. The image below shows the highlighted cells where it deviated from the Ideal Outcome.&amp;nbsp;&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="dkraeuter_sunne_0-1619561255001.png" style="width: 709px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32371iEB3DF816D5C77780/image-dimensions/709x481?v=v2" width="709" height="481" role="button" title="dkraeuter_sunne_0-1619561255001.png" alt="dkraeuter_sunne_0-1619561255001.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 22:10:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380280#M63061</guid>
      <dc:creator>dkraeuter_sunne</dc:creator>
      <dc:date>2021-04-27T22:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Increment a value for Run Number</title>
      <link>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380313#M63065</link>
      <description>&lt;P&gt;OK....my oversight again....I think the approach below solves the issue&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

// Create a column that when the data table is sorted, it can be returned to the original
dt &amp;lt;&amp;lt; New Column( "theRow", formula( Row() ) );

// Remove the formula to turn the values into static values
:theRow &amp;lt;&amp;lt; delete formula;

// Sort the data into an order where all Process ID for a given Shop Order are together
dt &amp;lt;&amp;lt; sort( by( :Shop Order, :Process ID, :theRow ), replace table( 1 ) );

// Create the Run # column
dt &amp;lt;&amp;lt; New Column( "Run #",
	formula(
		If( Row() == 1 | :Shop Order != Lag( :Shop Order ),
			count = 1,
			If( :Process ID != Lag( :Process ID ),
				count
				++)
		);
		count;
	)
);

// Remove the formula to turn the values into static values
:"Run #"n &amp;lt;&amp;lt; delete formula;

// Sort back into the original row order
dt &amp;lt;&amp;lt; sort( by( :theRow ), replace table( 1 ) );

// Delete the no longer needed theRow column
dt &amp;lt;&amp;lt; delete columns( :theRow );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Apr 2021 03:36:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Increment-a-value-for-Run-Number/m-p/380313#M63065</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-28T03:36:40Z</dc:date>
    </item>
  </channel>
</rss>

