<?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: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0 in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685153#M87107</link>
    <description>&lt;P&gt;This was actually exactly related to the discussion. The discussion is about eliminating error messages. Your suggestion does that. Thanks. Secondary goal was explanation of the necessity of "d0Row" variable in the original formula. This hasn't been resolved, but it really doesn't look as if it's required. Simplicity is desirable, of course.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2023 18:22:12 GMT</pubDate>
    <dc:creator>Ressel</dc:creator>
    <dc:date>2023-10-09T18:22:12Z</dc:date>
    <item>
      <title>Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/684974#M87094</link>
      <description>&lt;P&gt;I have received the &lt;A href="https://community.jmp.com/t5/Discussions/JMP-is-Not-a-Spreadsheet/m-p/333281/highlight/true#M58137" target="_blank" rel="noopener"&gt;formula I want to discuss&lt;/A&gt;&amp;nbsp;almost 3 years ago from&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;, never let go of it since and thought about it many times before now, slowly coming somewhat more seriously to grips with scripting. In the meantime, the formula as saved me &lt;STRONG&gt;a lot&lt;/STRONG&gt; of time.&lt;/P&gt;&lt;P&gt;In the example below, the same formula is added 3 times, each time with a little bit of variation. The issue I want to discuss are the different error messages thrown when copying and running the table script of the table including the newly added formula columns.&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 );

// first, we need an example table
dt = New Table( "ExampleTable",
	Add Rows( 24 ),
	New Column( "BatchId",
		Character,
		"Nominal",
		Set Values(
			{"A", "A", "A", "A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D",
			"D", "E", "E", "E", "F", "F", "F", "G", "G", "G"}
		)
	),
	New Column( "StorageCondition",
		Character,
		"Nominal",
		Set Values(
			{"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "5°C", "5°C", "5°C",
			"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
			"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
			"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
			"25°C/60%RH", "25°C/60%RH", "25°C/60%RH"}
		)
	),
	New Column( "Time",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
		)
	),
	New Column( "QcParameter",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[0.2, 0.3, 0.4, 0.2, 0.21, 0.22, 0.3, 0.9, 1.2, ., 0.2, 0.4, 0.1, ., 0.1,
			0, 0, 0, 0.1, 0, 0, 0, 0.1, 0]
		)
	)
);


// adding formula column via approach nr. 1&lt;BR /&gt;// this adds the formula alright, but when copying and executing the resulting table script will leave the formula column empty&lt;BR /&gt;// no need to discuss this, because this obviously missing the 'eval(eval expr(expr()))' wrapping (see screenshot below)
dt &amp;lt;&amp;lt; New Column( "QcParameter [% rel.]_1",
	numeric,
	formula(
		curBatch = :BatchId;
		curCondition = :StorageCondition;
		theRows = dt &amp;lt;&amp;lt; get rows where(
			:BatchId == curBatch &amp;amp; :StorageCondition == curCondition &amp;amp; :Time == 0
		);
		d0Row = theRows[1];
		d0Time = :QcParameter[d0Row];
		(100 * :QcParameter / d0Time);
	)
);


// adding formula column via approach nr. 2&lt;BR /&gt;// this will fill the formula column as desired when copying and running the table script with the added formula columns&lt;BR /&gt;// but it will also throw an error message when new rows are added to the table then (see screenshot below)
Eval(
	Eval Expr(
		dt &amp;lt;&amp;lt; New Column( "QcParameter [% rel.]_2",
			numeric,
			formula(
				curBatch = :BatchId;
				curCondition = :StorageCondition;
				theRows = Expr( dt ) &amp;lt;&amp;lt; get rows where(
					:BatchId == curBatch &amp;amp; :StorageCondition == curCondition &amp;amp; :Time == 0
				);
				d0Row = theRows[1]; // removed from approach nr. 3
				d0Time = :QcParameter[d0Row];
				(100 * :QcParameter / d0Time);
			)
		)
	)
);


// adding formula column via approach nr. 3
// this will fill the formula column as desired when copying and running the table script with the added formula columns&lt;BR /&gt;// and it will NOT throw an error message when new rows are added to the table then (see screenshot below)
Eval(
	Eval Expr(
		dt &amp;lt;&amp;lt; New Column( "QcParameter [% rel.]_3",
			numeric,
			formula(
				curBatch = :BatchId;
				curCondition = :StorageCondition;
				theRows = Expr( dt ) &amp;lt;&amp;lt; get rows where(
					:BatchId == curBatch &amp;amp; :StorageCondition == curCondition &amp;amp; :Time == 0
				);
				d0Time = :QcParameter[theRows];
				(100 * :QcParameter) / d0Time;
			)
		)
	)
);


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Screenshot of error message for formula column "QcParameter [%r rel.]_1]" when rerunning table script with additional formula columns:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ressel_0-1696856397171.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57301iEAF0330B30A2C951/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ressel_0-1696856397171.png" alt="Ressel_0-1696856397171.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Screenshot of error message for formula column "QcParameter [%r rel.]_2]" when rerunning table script with additional formula columns:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ressel_1-1696856568605.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57302iC9E8087A636A19B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ressel_1-1696856568605.png" alt="Ressel_1-1696856568605.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Screenshot of error message for formula column "QcParameter [%r rel.]_3]" when rerunning table script with additional formula columns:&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ressel_2-1696856674488.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57303i65BD2D7072DF76EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ressel_2-1696856674488.png" alt="Ressel_2-1696856674488.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason why I am asking this lengthy question is that I assume &lt;STRONG&gt;there must be some reason why variable "d0Row" is used in approach nr. 2, no?&lt;/STRONG&gt;&amp;nbsp;For approach nr. 3 I have simply deleted this variable (see screenshot below) and the formula behaves "much more nicely" as a result, i.e., there is no error message when new rows are added ad-hoc by point &amp;amp; click to the data table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ressel_3-1696856846545.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57304i31B1717124F3C995/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ressel_3-1696856846545.png" alt="Ressel_3-1696856846545.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My question is therefore, if I am doing something wrong by deleting the "d0Row" variable. In real life I am working with larger data tables and won't be able to check each row individually for its accuracy.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 13:20:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/684974#M87094</guid>
      <dc:creator>Ressel</dc:creator>
      <dc:date>2023-10-09T13:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/684995#M87095</link>
      <description>&lt;P&gt;I am not completely sure I am following your issue, but what I am seeing is that your reference to dt is when you copy formula 1, the reference to dt is missing.&amp;nbsp; In example 2 and 3, you end up with the data table reference pointing to data table "ExampleTable", and your data table name, as shown, is "Example Table 2".&amp;nbsp; Again, if I am understanding your issue,I think you can solve the issue by using "Current Daa Table()".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = Current Data Table() &amp;lt;&amp;lt; get rows where(
	:BatchId == curBatch &amp;amp; :StorageCondition == curCondition &amp;amp; :Time == 0
);
d0Row = theRows[1];
d0Time = :QcParameter[d0Row];
If( Row() == 11,
	Show( therows, d0Time )
);
(100 * :QcParameter) / d0Time;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 13:47:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/684995#M87095</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-10-09T13:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685011#M87098</link>
      <description>&lt;P&gt;Thanks! I'll try and summarize again:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;When adding the three formula columns to the example table previously without formula columns, then copying and executing the resulting table script of the table now containing the three formula columns, only examples 2 and 3 will populate the corresponding formula columns with the expected, relative values. The first formula column stays empty.&lt;/LI&gt;&lt;LI&gt;Moreover, when adding new rows to the final table created under 1. (i.e. from the table script containing now all 3 formula columns), only the third example will not throw an error message when adding new, empty rows.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Because of this observation I removed the "d0Row" variable as part of example 3. Following this, no error message appears when adding new rows to the table and it reproduces the relative data as expected. &lt;STRONG&gt;The question therefore is if "d0Row" is at all required&lt;/STRONG&gt;. I created example 3 specifically to test this hypothesis. (Removing "d0Row" makes the formula shorter, but my concern is that this variable is essential or that I am overlooking something. Am I?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure this is related to using or not using "current data table()" in the formula. I've used "current data table()" as a workaround for a long time now. This will still result in error messages when adding new rows to a table, but I still want to be able to add new rows to a table without having to constantly confirm error messages for every relative column in a table when a new row is added. There are dozens of relative columns in them and it costs time to repeat this operation. It is of course possible to suppress evaluation, but this also costs time. Apologies if this example is not clear, but I'm willing to explain further.)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 14:41:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685011#M87098</guid>
      <dc:creator>Ressel</dc:creator>
      <dc:date>2023-10-09T14:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685098#M87103</link>
      <description>&lt;P&gt;You should be able to eliminate the error messages with the Try() function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Try(
	curBatch = :BatchId;
	curCondition = :StorageCondition;
	theRows = Current Data Table() &amp;lt;&amp;lt; get rows where(
		:BatchId == curBatch &amp;amp; :StorageCondition == curCondition &amp;amp; :Time == 0
	);
	d0Row = theRows[1];
	d0Time = :QcParameter[d0Row];
	If( Row() == 11,
		Show( therows, d0Time )
	);
	(100 * :QcParameter) / d0Time;
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2023 15:26:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685098#M87103</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-10-09T15:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685134#M87104</link>
      <description>&lt;P&gt;Not exactly related to this question, but you can "simplify" the formula with some Col-function magics. These suggestions should work, but you should verify them before replacing old working formula&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column("FormulaA", Numeric, Continuous, Formula(
	100 * :QcParameter / Col Sum(If(:Time == 0, :QcParameter, .),:BatchID, :StorageCondition) 
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the data is sorted in such a way that Time 0 is always first for the group, you can make it even easier to understand (maybe)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column("FormulaB", Numeric, Continuous, Formula(
	100 * :QcParameter / QcParameter[Col Min(Row(), :BatchID, :StorageCondition)]
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 17:22:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685134#M87104</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-09T17:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685153#M87107</link>
      <description>&lt;P&gt;This was actually exactly related to the discussion. The discussion is about eliminating error messages. Your suggestion does that. Thanks. Secondary goal was explanation of the necessity of "d0Row" variable in the original formula. This hasn't been resolved, but it really doesn't look as if it's required. Simplicity is desirable, of course.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 18:22:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685153#M87107</guid>
      <dc:creator>Ressel</dc:creator>
      <dc:date>2023-10-09T18:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a column formula for standardizing time resolved data to 100% rel. at t=0</title>
      <link>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685164#M87109</link>
      <description>&lt;P&gt;Maybe d0Row is there &lt;STRONG&gt;just in case&lt;/STRONG&gt; if there could be multiple places where the time is 0 for each of the groups? Using d0Row you would only take first of those (my formulas for examples do not take that into account (sorting thing kinda does)).&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 19:02:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimizing-a-column-formula-for-standardizing-time-resolved-data/m-p/685164#M87109</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-09T19:02:11Z</dc:date>
    </item>
  </channel>
</rss>

