<?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: Problem with Lookup table / Loc sorted in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442275#M69055</link>
    <description>&lt;P&gt;Here is my take on solving the problem.&amp;nbsp; It handles the cases where either the Max Measurement is an even number, and therefore an exact row to get the Half Time from exists, or if the Max Measurement is an odd number, it will interpolate the Time value to come up with the Half Time value&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Data Table( "Data" );

dtSum = dt &amp;lt;&amp;lt; Summary(
	Group( :Sample, ),
	Max( :Measurement ),
	Freq( "None" ),
	Weight( "None" ),
	Link to Original Data Table( 0 ),
	Output Table( "The Summaries" )
);

dtSum &amp;lt;&amp;lt; New Column( "Half Max Measure", Set Each Value( :Name( "Max(Measurement)" ) / 2 ) );
dtSum &amp;lt;&amp;lt; New Column( "Time At Half Measurement", Format( "h:m:s" ) );

// Get the Half Max Measure
For( i = 1, i &amp;lt;= N Rows( dtSum ), i++,
	theRow = dt &amp;lt;&amp;lt; get rows where(
		dt:Sample == dtsum:Sample[i] &amp;amp; dt:Measurement == dtSum:Half Max Measure[i]
	);
	If( N Rows( theRow ) &amp;gt; 0,
		dtSum:Time At Half Measurement[i] = dt:Time[theRow[1]]
	, 
		// No Measurement was taken at exact Half Time, so interprolate the finding
		rowBefore = Max(
			dt &amp;lt;&amp;lt; get rows where(
				dt:Sample == dtsum:Sample[i] &amp;amp; dt:Measurement &amp;gt; dtSum:Half Max Measure[i]
			)
		);
		rowAfter = Min(
			dt &amp;lt;&amp;lt; get rows where(
				dt:Sample == dtsum:Sample[i] &amp;amp; dt:Measurement &amp;lt; dtSum:Half Max Measure[i]
			)
		);
		ratio = (dt:Measurement[rowBefore] - dtSum:Half Max Measure[i]) / (dt:Measurement[
		rowBefore] - dt:Measurement[rowAfter]);
		dtSum:Time At Half Measurement[i] = dt:Time[rowBefore] + ratio * (dt:Time[rowAfter] -
		dt:Time[rowBefore]);
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Dec 2021 15:15:29 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-12-03T15:15:29Z</dc:date>
    <item>
      <title>Problem with Lookup table / Loc sorted</title>
      <link>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442077#M69028</link>
      <description>&lt;P&gt;I am trying to find the time at which the measured value is half in this data table. My desired output would be a summary table with Time at half measurement by sample.&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="MrAB_0-1638519581314.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38126i6A95B78F2FD77898/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MrAB_0-1638519581314.png" alt="MrAB_0-1638519581314.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the summery table generated by the script and as you can see the time at half measure is not correct.&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="MrAB_1-1638519925559.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38127i25B6B73893D93BDB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MrAB_1-1638519925559.png" alt="MrAB_1-1638519925559.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made the following script that uses Loc sorted to look up the values from this table but i'm having difficulty getting it to work. Are there any errors in this script? Is this the right method for what I'm looking to do and if not does anyone have any suggestions on how I can do this? one thing to note is the half value might not match a time exactly so I will be looking for the time either before of after the half measure point.&amp;nbsp;&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);

Data Table( "Data" ) &amp;lt;&amp;lt; Summary(
	Group( :Sample, ),
	Max( :Measurement ),
	Freq( "None" ),
	Weight( "None" )
);

New Column( "Half Max Measure",	Formula	(:Name("Max(Measurement)") / 2));

New Column( "Time At Half Measurement",	Format ("h:m"), Formula(
dt = Data Table( "Data" );
If(dt:Sample == Sample,
Bracket = Loc Sorted( dt:Measurement &amp;lt;&amp;lt; getvalues, :Half Max Measure );
dt:Time[Bracket])));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:41:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442077#M69028</guid>
      <dc:creator>MrAB</dc:creator>
      <dc:date>2023-06-10T23:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Lookup table / Loc sorted</title>
      <link>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442202#M69047</link>
      <description>&lt;P&gt;"Loc Sorted" requires the first argument sorted to work properly.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="peng_liu_0-1638538030256.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38138i842BC52EBAAB594A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="peng_liu_0-1638538030256.png" alt="peng_liu_0-1638538030256.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;On the other hand, the following might give what you want, assuming the middle exist among data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;data table("Data") &amp;lt;&amp;lt; new column("is match", 
	formula(:Measurement == Col Max( :Measurement, :Sample ) / 2)
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the middle may not exist among data, check whether a sample falls within a range which you can define.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 13:31:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442202#M69047</guid>
      <dc:creator>peng_liu</dc:creator>
      <dc:date>2021-12-03T13:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Lookup table / Loc sorted</title>
      <link>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442275#M69055</link>
      <description>&lt;P&gt;Here is my take on solving the problem.&amp;nbsp; It handles the cases where either the Max Measurement is an even number, and therefore an exact row to get the Half Time from exists, or if the Max Measurement is an odd number, it will interpolate the Time value to come up with the Half Time value&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Data Table( "Data" );

dtSum = dt &amp;lt;&amp;lt; Summary(
	Group( :Sample, ),
	Max( :Measurement ),
	Freq( "None" ),
	Weight( "None" ),
	Link to Original Data Table( 0 ),
	Output Table( "The Summaries" )
);

dtSum &amp;lt;&amp;lt; New Column( "Half Max Measure", Set Each Value( :Name( "Max(Measurement)" ) / 2 ) );
dtSum &amp;lt;&amp;lt; New Column( "Time At Half Measurement", Format( "h:m:s" ) );

// Get the Half Max Measure
For( i = 1, i &amp;lt;= N Rows( dtSum ), i++,
	theRow = dt &amp;lt;&amp;lt; get rows where(
		dt:Sample == dtsum:Sample[i] &amp;amp; dt:Measurement == dtSum:Half Max Measure[i]
	);
	If( N Rows( theRow ) &amp;gt; 0,
		dtSum:Time At Half Measurement[i] = dt:Time[theRow[1]]
	, 
		// No Measurement was taken at exact Half Time, so interprolate the finding
		rowBefore = Max(
			dt &amp;lt;&amp;lt; get rows where(
				dt:Sample == dtsum:Sample[i] &amp;amp; dt:Measurement &amp;gt; dtSum:Half Max Measure[i]
			)
		);
		rowAfter = Min(
			dt &amp;lt;&amp;lt; get rows where(
				dt:Sample == dtsum:Sample[i] &amp;amp; dt:Measurement &amp;lt; dtSum:Half Max Measure[i]
			)
		);
		ratio = (dt:Measurement[rowBefore] - dtSum:Half Max Measure[i]) / (dt:Measurement[
		rowBefore] - dt:Measurement[rowAfter]);
		dtSum:Time At Half Measurement[i] = dt:Time[rowBefore] + ratio * (dt:Time[rowAfter] -
		dt:Time[rowBefore]);
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 15:15:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Problem-with-Lookup-table-Loc-sorted/m-p/442275#M69055</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-12-03T15:15:29Z</dc:date>
    </item>
  </channel>
</rss>

