<?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: Beginner trying to Write Script / How to iterate within the formula function? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844936#M101940</link>
    <description>&lt;P&gt;Missing value is there to attempt to "force" the Col Min to have only one option to pick from as it will ignore missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can break this type of formulas into multiple parts in attempt to understand them better (sometimes they can still be very cryptic)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//col1
Col Min(:Date Number Format, :Unique_Fruit)

//col2
:Date Number Format == :col1

//col3
If(:col2, :Key_Taste, .)

//col4
Col Min(:col3, :Unique_Fruit)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1740727204945.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/73464iCC6992E7632C9F6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1740727204945.png" alt="jthi_0-1740727204945.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2025 07:20:49 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-02-28T07:20:49Z</dc:date>
    <item>
      <title>Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844919#M101933</link>
      <description>&lt;P&gt;HI, I am a beginner at script writing in any language.&amp;nbsp; I am currently meandering through what I thought would be a simple practice task.&amp;nbsp; I am using JMP18.&amp;nbsp; My goal is to automate a routine operation that I do with growing datasets over time.&amp;nbsp; The routine operation is to first determine the time scale, and then show the change in data over that time scale for large datasets. The basic way I am approaching this is creating new columns to fill in all the initial data and using formulas on more columns to get differences.&amp;nbsp; If someone has a better suggestion, I'd appreciate it.&amp;nbsp; Below is where I am at:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I have a set of data and I want to achieve the following.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) I am looking to take the date and time columns, bring them together into a single column, and then I find the minimum, and use that to create a starting date.&amp;nbsp; I can then subtract the times to see the difference in time between data.&amp;nbsp; This was all simple enough with the formula() functions.&amp;nbsp; Everything here works great.&lt;/P&gt;&lt;P&gt;2) I want to do something similar to several of the data columns, but I cannot do what I did before to find the initial value.&amp;nbsp; The initial data is determined by the minimum time found in what I did before for every unique item in a third column (called Unique_Fruit in the code below).&amp;nbsp; For the sake of this forum, for each unique_fruit, i want to create a column that contains the initial values of data for that fruit so i can then quickly calculate the changes from the actual data column.&lt;BR /&gt;&lt;BR /&gt;My current JSL script is below.&amp;nbsp; I have a dummy code formula where I haven't figured out what to do.&amp;nbsp; It is the steps where I used the If function, found the times equal each other and set the value for only those cells.&amp;nbsp; My original thought was to try using a for loop and iterate in the formula, but that did not seem to work.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;DataTable = Current Data Table();  

New Column( "Date Number Format", Numeric, "Continuous" );

For( i = 1, i &amp;lt;= N Rows( DataTable ), i++,
    DataTable:Date Number Format[i] = Num( DataTable:Key_Date[i] );
);

New Column( "Time Number Format", Numeric, "Continuous" );

For( i = 1, i &amp;lt;= N Rows( DataTable ), i++,
    DataTable:Time Number Format[i] = Num( DataTable:Key_Time[i] ); 
);

New Column( "Current_Time", Numeric, "Continuous" );

For( i = 1, i &amp;lt;= N Rows( DataTable ), i++,
    DataTable:Current_Time[i] = DataTable:Date Number Format[i] + DataTable:Time Number Format[i]; 
);

New Column( "Unique_Fruit", Character, "Nominal" );

For( i = 1, i &amp;lt;= N Rows( DataTable ), i++,
    DataTable:Unique_Fruit[i] = DataTable:Fruit[i] || "-" || DataTable:Type[i];  
);

New Column( "Starting_Date_Number_Format", Numeric, "Continuous", 
    Formula( Col Minimum( :Current_Time, :Unique_Fruit ) )
);

New Column( "Minutes", Numeric, "Continuous", 
    Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Minute", "fractional" ) )
);

New Column( "Days", Numeric, "Continuous", 
    Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Day", "fractional" ) )
);

New Column( "Weeks", Numeric, "Continuous", 
    Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Week", "fractional" ) )
);

New Column( "Months", Numeric, "Continuous", 
    Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Month", "fractional" ) )
);

New Column( "Initial_Taste", Numeric, "Continuous", 
    Formula( 
        If( :Current_Time == :Starting_Date_Number_Format, :Key_Taste, . ) 
    )
);

For( i = 1, i &amp;lt;= N Rows( DataTable ), i++,
    If( DataTable:Current_Time[i] == DataTable:Starting_Date_Number_Format[i], 
        DataTable:Initial_Taste[i] = DataTable:Key_Taste[i];
    );
);

New Column( "Delta_Taste", Numeric, "Continuous", 
    Formula( :Key_Taste - :Initial_Taste )
);

New Column( "%_Change_Taste", Numeric, "Continuous", 
    Formula( ( :Delta_Taste / :Initial_Taste ) * 100 + 100 )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 03:33:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844919#M101933</guid>
      <dc:creator>bub</dc:creator>
      <dc:date>2025-02-28T03:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844929#M101934</link>
      <description>&lt;P&gt;Can you provide example dataset + column with correct answer? Most likely you can get the initial values using something like this, but you have to modify the comparison as this one gets first value for each category&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Col Cumulative Sum(If(Row() == Col Min(Row(), :age), :height, .), :age)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where :age is unique_fruit and :height is your value column. You can also utilize Lag() and variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are also some changes I would do to your script to make it a bit more robust.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Start your script with Names Default To Here(1);&lt;/LI&gt;
&lt;LI&gt;As you have reference to a datatable use it
&lt;OL&gt;
&lt;LI&gt;DataTable &amp;lt;&amp;lt; New Column(...&lt;/LI&gt;
&lt;LI&gt;I would also consider changing DataTable to dt or something similar as JMP has function called Datatable()&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;When looping over datatable use For Each Row instead of For as it is its special use case&lt;/LI&gt;
&lt;LI&gt;When you wish to have new columns in JMP table without having formulas you have few options:
&lt;OL&gt;
&lt;LI&gt;Use New column + Formula + run formulas + delete formula combination&lt;/LI&gt;
&lt;LI&gt;Create new column and loop over the data table (like you are doing)&lt;/LI&gt;
&lt;LI&gt;Then there is a bit finnicky method of using &amp;lt;&amp;lt; Apply Formula but I would keep to those first (usually I use the first one)&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 28 Feb 2025 05:02:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844929#M101934</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-28T05:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844930#M101935</link>
      <description>&lt;P&gt;Welcome to the Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with Jarmo, a sample data table.&lt;/P&gt;
&lt;P&gt;I also suggest that you provide a mocked up example of what your expected results are.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 05:20:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844930#M101935</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2025-02-28T05:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844931#M101936</link>
      <description>&lt;P&gt;Thank you for the suggestion.&amp;nbsp; I am attempting a mock dataset and what I currently do manually. To set the initial values, I look at each unique item and call for the data from that cell and populate the whole column so I can then move on to the next part of the calculation.&amp;nbsp; I'll try updating the rest of the script with your suggestions as well, but the main issue is not solved just yet I think for me (or I I haven't understood just yet.)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 05:51:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844931#M101936</guid>
      <dc:creator>bub</dc:creator>
      <dc:date>2025-02-28T05:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844932#M101937</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/65615"&gt;@bub&lt;/a&gt;&amp;nbsp;, please have a look at&amp;nbsp;&lt;A href="https://marketplace.jmp.com/appdetails/Normalization+GUI" target="_blank"&gt;https://marketplace.jmp.com/appdetails/Normalization+GUI&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It facilitates the task&amp;nbsp;to normalize data by an initial value (subtract or divide) - per group.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 06:47:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844932#M101937</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-02-28T06:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844933#M101938</link>
      <description>&lt;P&gt;It wasn't solved as it generally takes more time to create mockup data than answer the &lt;STRONG&gt;correct&lt;/STRONG&gt; question. You should be able to utilize something like this for initial values&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Col Min(If(:Date Number Format == Col Min(:Date Number Format, :Unique_Fruit), :Key_Taste, .), :Unique_Fruit)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This isn't the only way of building these, but something like this does work quite often&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 06:51:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844933#M101938</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-28T06:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844934#M101939</link>
      <description>&lt;P&gt;Thank you very much.&amp;nbsp; Just to clarify, I wasn't trying to put blame on your first response, more so that I was trying to implement it on a few iterations and thought I was still missing something.&amp;nbsp; I should have kept going because I probably would have ended up at the answer you showed here (eventually), but as I said earlier I am new to scripting these things so it is slow going.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Out of curiosity, why have the "." in the else?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 07:07:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844934#M101939</guid>
      <dc:creator>bub</dc:creator>
      <dc:date>2025-02-28T07:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844936#M101940</link>
      <description>&lt;P&gt;Missing value is there to attempt to "force" the Col Min to have only one option to pick from as it will ignore missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can break this type of formulas into multiple parts in attempt to understand them better (sometimes they can still be very cryptic)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//col1
Col Min(:Date Number Format, :Unique_Fruit)

//col2
:Date Number Format == :col1

//col3
If(:col2, :Key_Taste, .)

//col4
Col Min(:col3, :Unique_Fruit)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1740727204945.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/73464iCC6992E7632C9F6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1740727204945.png" alt="jthi_0-1740727204945.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 07:20:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844936#M101940</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-28T07:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844941#M101942</link>
      <description>&lt;P&gt;In future, tasks like this one will get super easy:&lt;BR /&gt;&lt;A href="https://community.jmp.com/t5/JMP-Wish-List/Group-by-sooo-useful-how-about-Interpolate/idc-p/828679/highlight/true#M6896" target="_blank"&gt;https://community.jmp.com/t5/JMP-Wish-List/Group-by-sooo-useful-how-about-Interpolate/idc-p/828679/highlight/true#M6896&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Together with Col Interpolate, many new functions (and functionalities) will be added to the Col aggregations :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 08:30:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/844941#M101942</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-02-28T08:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/845064#M101962</link>
      <description>&lt;P&gt;Hey, I had an additional thought as I am playing around with this.&amp;nbsp; If I wanted to do something closer to what I originally thought I had to do when I posted this, how is it done?&amp;nbsp; Where I am at is writing a variable that stores a list and then trying to have the code iterate through that list to populate the formula.&amp;nbsp; Instead of populating the variable remains inside the formula rather than updating to one of the list values. Is that something that can be done within the formula function?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 21:42:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/845064#M101962</guid>
      <dc:creator>bub</dc:creator>
      <dc:date>2025-02-28T21:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/845065#M101963</link>
      <description>&lt;P&gt;Thank you for the explanation here.&amp;nbsp; I am playing around with it as I continue on this small project for myself and seeing where I can take it.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 21:44:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/845065#M101963</guid>
      <dc:creator>bub</dc:creator>
      <dc:date>2025-02-28T21:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner trying to Write Script / How to iterate within the formula function?</title>
      <link>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/845096#M101971</link>
      <description>&lt;P&gt;You can get a list of values/collect a list of values inside a formula but you have to be just careful how you update the values (using As Constant or If(Row() == 1,...) can help). Also you might want to avoid loops inside formulas as they do trigger quite often. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use Lag() but this would require your data to be sorted (can be done without sorting, but it can quickly get complicated) but usually the idea is something a bit like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() == 1,
	init_taste = :Key_Taste
);

If(:Unique_Fruit != Lag(:Unique_Fruit),
	init_taste = :Key_Taste;
);

init_taste;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do note that I did sort the data by Date Number Format and Unique_Fruit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Mar 2025 05:49:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Beginner-trying-to-Write-Script-How-to-iterate-within-the/m-p/845096#M101971</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-03-01T05:49:10Z</dc:date>
    </item>
  </channel>
</rss>

