<?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: Selecting and removing duplicates row with condition in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220642#M44095</link>
    <description>&lt;P&gt;There is a function called&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Select Duplicate Rows()&lt;/P&gt;
&lt;P&gt;that can be used for this, however it is based upon finding rows following a unique row.&amp;nbsp; Therefore, the table needs to be sorted in reverse before using the function.&amp;nbsp; Below is a sample script to do this.&amp;nbsp; Since I did not have a sample data table to run this on, the script has not been tested, however it is very close to being what you need.&lt;/P&gt;
&lt;P&gt;Documentation on the function can be found in the Scripting Index&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Help==&amp;gt;Scripting Indes&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

// Add a new column to preserve the current order
dt &amp;lt;&amp;lt; New Column( "rowNum", formula( Row() ) );
// Remove the formula to convert values to static values
:rowNum &amp;lt;&amp;lt; delete property( "formula" );

// Sort the data table in referse order, since one wants to 
// keep the most recent value
dt &amp;lt;&amp;lt; sort( by( rowNum ), order( descending ), Replace Table( 1 ) );

// Find the duplicate rows
dt &amp;lt;&amp;lt; Select Duplicate Rows( Match( :SerialNo, :Date, :Retest ) );

// Delete Duplicates
dt &amp;lt;&amp;lt; delete rows;

// Reorder the table
dt &amp;lt;&amp;lt; sort( by( rowNum ), order( ascending ), Replace Table( 1 ) );

// Delete rowNum column
dt &amp;lt;&amp;lt; delete columns( "rowNum" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Aug 2019 08:40:41 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2019-08-08T08:40:41Z</dc:date>
    <item>
      <title>Selecting and removing duplicates row with condition</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220631#M44093</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've searched around the forum however didnt come close to what I wanted to achieve, or maybe I missed out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sorting.jpg" style="width: 840px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/18708i673AF6322E113C77/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sorting.jpg" alt="Sorting.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Anyway, I need help on the table above. As can be seen, I have duplicates as per highlighted by color. The serial number is same for most part because the part is inspected on different section(as show 1A,1B,2A,2B,3A,3B,4A,4B). Usually if the part fails inspection it will be re-inspected, which show in the re-test column(0 for no retest, 1 for 1st, etc..) Now I can only differentiate the part by the number of retest or date within the same serial number, so I would like to retain the latest re-test result and delete the duplicates of previous. Meaning to say as per highlighted box above, for the blue or red, I want to retain the re-test 1 and remove the re-test 0. This is kinda headache for me, so I would need community's advise on the script to select the condition within the serial number and section to figure out the&amp;nbsp; latest re-test, then retain the latest re-test and remove previous duplicates. I hope you all have any input for this. Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 06:54:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220631#M44093</guid>
      <dc:creator>OtisZeca</dc:creator>
      <dc:date>2019-08-08T06:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting and removing duplicates row with condition</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220642#M44095</link>
      <description>&lt;P&gt;There is a function called&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Select Duplicate Rows()&lt;/P&gt;
&lt;P&gt;that can be used for this, however it is based upon finding rows following a unique row.&amp;nbsp; Therefore, the table needs to be sorted in reverse before using the function.&amp;nbsp; Below is a sample script to do this.&amp;nbsp; Since I did not have a sample data table to run this on, the script has not been tested, however it is very close to being what you need.&lt;/P&gt;
&lt;P&gt;Documentation on the function can be found in the Scripting Index&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Help==&amp;gt;Scripting Indes&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

// Add a new column to preserve the current order
dt &amp;lt;&amp;lt; New Column( "rowNum", formula( Row() ) );
// Remove the formula to convert values to static values
:rowNum &amp;lt;&amp;lt; delete property( "formula" );

// Sort the data table in referse order, since one wants to 
// keep the most recent value
dt &amp;lt;&amp;lt; sort( by( rowNum ), order( descending ), Replace Table( 1 ) );

// Find the duplicate rows
dt &amp;lt;&amp;lt; Select Duplicate Rows( Match( :SerialNo, :Date, :Retest ) );

// Delete Duplicates
dt &amp;lt;&amp;lt; delete rows;

// Reorder the table
dt &amp;lt;&amp;lt; sort( by( rowNum ), order( ascending ), Replace Table( 1 ) );

// Delete rowNum column
dt &amp;lt;&amp;lt; delete columns( "rowNum" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2019 08:40:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220642#M44095</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-08-08T08:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting and removing duplicates row with condition</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220969#M44097</link>
      <description>&lt;P&gt;If you have an earlier version of JMP, &lt;EM&gt;&amp;lt;&amp;lt;Select Duplicate Rows&lt;/EM&gt; may not be available. Then try the below approach. The code should select and delete the duplicate rows (based on matching SerialNo and Section) with the earliest date. Sorting does not matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
dt &amp;lt;&amp;lt; select where(Col Max(:Date, :SerialNo, :Section) &amp;gt; :Date());
dt &amp;lt;&amp;lt; delete rows();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2019 10:43:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220969#M44097</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2019-08-08T10:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting and removing duplicates row with condition</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/221095#M44123</link>
      <description>&lt;P&gt;I made abit of amendments to suit my table. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 01:02:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/221095#M44123</guid>
      <dc:creator>OtisZeca</dc:creator>
      <dc:date>2019-08-09T01:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting and removing duplicates row with condition</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/221096#M44124</link>
      <description>&lt;P&gt;Great help! Thanks!&lt;/P&gt;&lt;P&gt;I was building a something like this, somehow my combination got wrong on the column selection.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 01:04:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/221096#M44124</guid>
      <dc:creator>OtisZeca</dc:creator>
      <dc:date>2019-08-09T01:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting and removing duplicates row with condition</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/690231#M87615</link>
      <description>&lt;P&gt;If you want to remove duplicate rows matching all columns except one(or a few), this is my working solution.&lt;BR /&gt;Advantage is no need to specify every column name.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// delete duplicate rows, where only column ID is different 
	column_list = dtProcess &amp;lt;&amp;lt; Get Column Names( string );		
	Remove From( column_list, As List( Loc( column_list, "ID" ) ) ); // remove "ID"
	dtProcess &amp;lt;&amp;lt; Select Duplicate Rows( Match(As List(column_list)));
	doublerows = dtProcess &amp;lt;&amp;lt; get selected rows;
	num_selected = n rows(doublerows);	
	if(num_selected &amp;gt;0, 
		dtProcess &amp;lt;&amp;lt; delete rows;
		print("Removed " || char(num_selected) || " rows from process table.")
		,
		print("No duplicate rows in process table, excluding column ID.")
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;:&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 04:55:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/690231#M87615</guid>
      <dc:creator>u757707</dc:creator>
      <dc:date>2023-10-25T04:55:08Z</dc:date>
    </item>
  </channel>
</rss>

