<?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 make a new column with experiment number in a data table with stacked repeating continuous data? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870027#M103305</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/65729"&gt;@WhiteCow2000&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had a crack at this by taking the position where '1' appears, marking each of them with an increasing number, then copying the Fill &amp;gt; Replace Missing with Previous Value option that can be done manually in JMP. I added a window for you to select your column that is to be measured to make it more flexible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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; Clear Column Selection();
//This will work to find the instance where the lowest number (1 in this case) appears in the row order, if the rows are sorted in any way then it will adapt to that so be careful.
//Window to select the column with repeats
nw = New Window( "Launch Dialog",
    &amp;lt;&amp;lt;Modal,
    V List Box( Align( "right" ),
        H List Box(
            Panel Box( "Select Columns",
            //Filter for continuous data only
                clb = Filter Col Selector( dt, All,&amp;lt;&amp;lt;continuous(1), &amp;lt;&amp;lt;ordinal(0), &amp;lt;&amp;lt;nominal(0))
            ),
            Panel Box( "Pick Experiment Repeat Column",
                Lineup Box( N Col( 2 ), Spacing( 5 ),
                    Button Box( "Columns",
                        clbY &amp;lt;&amp;lt; Append( clb &amp;lt;&amp;lt; Get Selected )
                    ),
                    clbY = Col List Box(
                        "Numeric",
                        MinItems( 1 ),
                        MaxItems( 1 ),
                        nlines( 5 )
                    ),
                    Button Box( "Remove",
                        clbY &amp;lt;&amp;lt; Remove Selected
                    )
                )
            )
        ),
        H List Box(
            Button Box( "OK",
            (
                cols = clby &amp;lt;&amp;lt; Get Items( "Column Reference" );
                 run;);
            ),
            Button Box( "Cancel" )
        )
    )
);

//Expression that runs the steps to mark out the rows
run=expr(
//Add a column to track experiment number
dt&amp;lt;&amp;lt;new column("Experiment No","Character");

//Find the points where "1" appears in the selected column
val=dt&amp;lt;&amp;lt;Get rows where (cols == 1);


//Mark each instance where 1 appears with an iteration from 1, 2, 3....
For(i=1, i&amp;lt;(N items(val)+1), i++,
dt:Experiment No[(val[i])] = i;);

//JSL Version of 'Fill Replace missing values...' Example taken from https://community.jmp.com/t5/Discussions/Fill-empty-cells-with-last-valid-value/m-p/30782#U30782
For( i = 2, i &amp;lt;= N Rows( dt ), i++,
	If( Is Missing( :Experiment No[i] ),
		:Experiment No[i] = :Experiment No[i - 1]
	)
);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The simple version of the script where you would type the exact column names in JSL is here:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data Table ();

//This will work to find the instance where the lowest number (1 in this case) appears in the row order, if the rows are sorted in any way
//Window to select the column with repeats

//Add a column to track experiment number
dt&amp;lt;&amp;lt;new column("Experiment No","Character");

//Find the points where "1" appears
val=dt&amp;lt;&amp;lt;Get rows where (:Column 1 == 1);
For(i=1, i&amp;lt;(N items(val)+1), i++,
dt:Column 2[(val[i])] = i;);

//JSL Version of 'Fill Replace missing values...' Example taken from https://community.jmp.com/t5/Discussions/Fill-empty-cells-with-last-valid-value/m-p/30782#U30782
For( i = 2, i &amp;lt;= N Rows( dt ), i++,
	If( Is Missing( :Experiment No[i] ),
		:Experiment No[i] = :Experiment No[i - 1]
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Apr 2025 13:54:07 GMT</pubDate>
    <dc:creator>Ben_BarrIngh</dc:creator>
    <dc:date>2025-04-24T13:54:07Z</dc:date>
    <item>
      <title>How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866952#M102964</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data table with repeating continuous experiments. So the data is already stacked. I have a column where each new experiment starts with 1 then 2 and so on until last measurement. I want to create a new column with experiment number, so every time the other column starts with 1 that is the start of another experiment.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried writing this script with help from AI but it does not work. Hope somebody can help me on this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dt = Current Data Table(); &lt;BR /&gt;&lt;BR /&gt;// Column used to identify new experiments &lt;BR /&gt;experimentIdentifier = Column(dt, "Column1"); // It is Column1 that contains numbers from 1 to 100 repeating over and over.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;// Create a new column for sample numbers &lt;BR /&gt;dt &amp;lt;&amp;lt; New Column("SampleNumber", Numeric); &lt;BR /&gt;&lt;BR /&gt;// Initialize variables &lt;BR /&gt;currentExperiment = experimentIdentifier[1]; &lt;BR /&gt;sampleNumber = 1; &lt;BR /&gt;&lt;BR /&gt;// Iterate over each row using explicit row indexing &lt;BR /&gt;For(i = 1, i &amp;lt;= N Row(dt), i++, &lt;BR /&gt;If(experimentIdentifier[i] != currentExperiment, &lt;BR /&gt;// New experiment starts, reset sample number &lt;BR /&gt;currentExperiment = experimentIdentifier[i]; &lt;BR /&gt;sampleNumber = 1; &lt;BR /&gt;, &lt;BR /&gt;// Otherwise, increment sample number &lt;BR /&gt;sampleNumber++; &lt;BR /&gt;); &lt;BR /&gt;&lt;BR /&gt;// Assign sample number to the new column &lt;BR /&gt;dt:SampleNumber[i] = sampleNumber; &lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:22:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866952#M102964</guid>
      <dc:creator>WhiteCow2000</dc:creator>
      <dc:date>2025-04-08T19:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866964#M102966</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;Create a new column and set this as the formula:&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRIKE&gt;&lt;CODE class=" language-jsl"&gt;Col Cumulative Sum( 1, :Column 1 )&lt;/CODE&gt;&lt;/STRIKE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRIKE&gt;Column 1 being the column that contains the measurement numbers.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Brain fart.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:01:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866964#M102966</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-04-08T20:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866965#M102967</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Length( Loc( :Column 1[1 :: Row()], 1 ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That formula works.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:06:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866965#M102967</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-04-08T20:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866966#M102968</link>
      <description>&lt;P&gt;You can use Col Cumulative Sum(), but it's not as pretty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Col Cumulative Sum( If( :Column 1 == 1, :Column 1, 0 ) )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:18:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/866966#M102968</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-04-08T20:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870024#M103304</link>
      <description>&lt;P&gt;I don't understand how to use this in a script.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have also tried this, but so far all rows in my new column have a value of 1. Can you see what is not working?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dt = current data Table () &amp;lt;&amp;lt; New Column("Experiment No", &lt;BR /&gt;Numeric, &lt;BR /&gt;Formula( &lt;BR /&gt;If( Row() == 1, 1, // Initialize experiment number as 1 for the first row &lt;BR /&gt;If( :Point No. == 1 &amp;amp; Lag(:Point No.) != 1, Lag(:Experiment No) + 1, // Increment experiment number if "Point No." resets to 1 &lt;BR /&gt;Lag(:Experiment No, 1) // Otherwise, keep the same experiment number &lt;BR /&gt;) &lt;BR /&gt;) &lt;BR /&gt;) &lt;BR /&gt;);&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 13:08:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870024#M103304</guid>
      <dc:creator>WhiteCow2000</dc:creator>
      <dc:date>2025-04-24T13:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870027#M103305</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/65729"&gt;@WhiteCow2000&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had a crack at this by taking the position where '1' appears, marking each of them with an increasing number, then copying the Fill &amp;gt; Replace Missing with Previous Value option that can be done manually in JMP. I added a window for you to select your column that is to be measured to make it more flexible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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; Clear Column Selection();
//This will work to find the instance where the lowest number (1 in this case) appears in the row order, if the rows are sorted in any way then it will adapt to that so be careful.
//Window to select the column with repeats
nw = New Window( "Launch Dialog",
    &amp;lt;&amp;lt;Modal,
    V List Box( Align( "right" ),
        H List Box(
            Panel Box( "Select Columns",
            //Filter for continuous data only
                clb = Filter Col Selector( dt, All,&amp;lt;&amp;lt;continuous(1), &amp;lt;&amp;lt;ordinal(0), &amp;lt;&amp;lt;nominal(0))
            ),
            Panel Box( "Pick Experiment Repeat Column",
                Lineup Box( N Col( 2 ), Spacing( 5 ),
                    Button Box( "Columns",
                        clbY &amp;lt;&amp;lt; Append( clb &amp;lt;&amp;lt; Get Selected )
                    ),
                    clbY = Col List Box(
                        "Numeric",
                        MinItems( 1 ),
                        MaxItems( 1 ),
                        nlines( 5 )
                    ),
                    Button Box( "Remove",
                        clbY &amp;lt;&amp;lt; Remove Selected
                    )
                )
            )
        ),
        H List Box(
            Button Box( "OK",
            (
                cols = clby &amp;lt;&amp;lt; Get Items( "Column Reference" );
                 run;);
            ),
            Button Box( "Cancel" )
        )
    )
);

//Expression that runs the steps to mark out the rows
run=expr(
//Add a column to track experiment number
dt&amp;lt;&amp;lt;new column("Experiment No","Character");

//Find the points where "1" appears in the selected column
val=dt&amp;lt;&amp;lt;Get rows where (cols == 1);


//Mark each instance where 1 appears with an iteration from 1, 2, 3....
For(i=1, i&amp;lt;(N items(val)+1), i++,
dt:Experiment No[(val[i])] = i;);

//JSL Version of 'Fill Replace missing values...' Example taken from https://community.jmp.com/t5/Discussions/Fill-empty-cells-with-last-valid-value/m-p/30782#U30782
For( i = 2, i &amp;lt;= N Rows( dt ), i++,
	If( Is Missing( :Experiment No[i] ),
		:Experiment No[i] = :Experiment No[i - 1]
	)
);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The simple version of the script where you would type the exact column names in JSL is here:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data Table ();

//This will work to find the instance where the lowest number (1 in this case) appears in the row order, if the rows are sorted in any way
//Window to select the column with repeats

//Add a column to track experiment number
dt&amp;lt;&amp;lt;new column("Experiment No","Character");

//Find the points where "1" appears
val=dt&amp;lt;&amp;lt;Get rows where (:Column 1 == 1);
For(i=1, i&amp;lt;(N items(val)+1), i++,
dt:Column 2[(val[i])] = i;);

//JSL Version of 'Fill Replace missing values...' Example taken from https://community.jmp.com/t5/Discussions/Fill-empty-cells-with-last-valid-value/m-p/30782#U30782
For( i = 2, i &amp;lt;= N Rows( dt ), i++,
	If( Is Missing( :Experiment No[i] ),
		:Experiment No[i] = :Experiment No[i - 1]
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Apr 2025 13:54:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870027#M103305</guid>
      <dc:creator>Ben_BarrIngh</dc:creator>
      <dc:date>2025-04-24T13:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870038#M103307</link>
      <description>&lt;P&gt;AI is pretty bad with JSL.&amp;nbsp; Applying my solution is straightforward.&amp;nbsp; Also, I tried your last formula, and it worked fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( New Column( "Point No.", Set Values( Repeat( 1 :: 100, 4 ) ) ) );
dt &amp;lt;&amp;lt; New Column( "Experiment No", Numeric, Formula( Length( Loc( :Point No.[1 :: Row()], 1 ) ) ) );
dt &amp;lt;&amp;lt; New Column( "Experiment No", Numeric, Formula( Col Cumulative Sum( If( :Point No. == 1, :Point No., 1, 0 ) ) ) );
dt &amp;lt;&amp;lt; New Column( "Experiment No",
	Numeric,
	Formula(
		If( Row() == 1,
			1, // Initialize experiment number as 1 for the first row
			If( :Point No. == 1&lt;SPAN&gt;&amp;nbsp;&amp;amp; Lag(:Point No.) != 1&lt;/SPAN&gt;,
				Lag( :Experiment No ) + 1, // Increment experiment number if "Point No." resets to 1
				Lag( :Experiment No, 1 ) // Otherwise, keep the same experiment number
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&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="mmarchandFSLR_0-1745503787855.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75155i60D8E4D28FC5092B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mmarchandFSLR_0-1745503787855.png" alt="mmarchandFSLR_0-1745503787855.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 14:09:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870038#M103307</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-04-24T14:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870192#M103333</link>
      <description>&lt;P&gt;Thank you so much for all your help! It works now with both If formula and the Length formula!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 05:00:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/870192#M103333</guid>
      <dc:creator>WhiteCow2000</dc:creator>
      <dc:date>2025-04-25T05:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new column with experiment number in a data table with stacked repeating continuous data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/873531#M103760</link>
      <description>&lt;P&gt;Returning to this thread a few weeks later to share a nice solution to a similar problem, which I think might work better with a simpler formula:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/How-to-get-new-column-to-populate-cycles-in-large-data-set-for/td-p/872921" target="_blank"&gt;Solved: How to get new column to populate cycles in large data set for multiple cycles o... - JMP User Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 08:15:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-new-column-with-experiment-number-in-a-data-table/m-p/873531#M103760</guid>
      <dc:creator>christian-z</dc:creator>
      <dc:date>2025-05-14T08:15:37Z</dc:date>
    </item>
  </channel>
</rss>

