<?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 find first element with condition in a column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374921#M62464</link>
    <description>&lt;P&gt;Hi, I have a data with 2 columns: group and score, and I want to calculate the 3rd column called first, which returns the "first score by group that is not&amp;nbsp;10000000000. so in this sample data, group a = 0, group b =53. and since group c only contains 10000000000, nothing shows up for it.&lt;/P&gt;&lt;P&gt;Could someone help me with a jmp formula for this column but not jsl? Thank you so much!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;group&lt;/TD&gt;&lt;TD&gt;score&lt;/TD&gt;&lt;TD&gt;first&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Fri, 09 Jun 2023 00:31:47 GMT</pubDate>
    <dc:creator>joann</dc:creator>
    <dc:date>2023-06-09T00:31:47Z</dc:date>
    <item>
      <title>find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374921#M62464</link>
      <description>&lt;P&gt;Hi, I have a data with 2 columns: group and score, and I want to calculate the 3rd column called first, which returns the "first score by group that is not&amp;nbsp;10000000000. so in this sample data, group a = 0, group b =53. and since group c only contains 10000000000, nothing shows up for it.&lt;/P&gt;&lt;P&gt;Could someone help me with a jmp formula for this column but not jsl? Thank you so much!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;group&lt;/TD&gt;&lt;TD&gt;score&lt;/TD&gt;&lt;TD&gt;first&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;10000000000&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 00:31:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374921#M62464</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2023-06-09T00:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374940#M62467</link>
      <description>&lt;P&gt;Here is one way to write the formula&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;curgroup = :group;
value = :score[Min(
	Current Data Table() &amp;lt;&amp;lt; get rows where(
		:group == curgroup &amp;amp; :score != 10000000000
	)
)];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 17:39:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374940#M62467</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-07T17:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374977#M62471</link>
      <description>&lt;P&gt;Hi Jim, thank you for the answer. I pasted it into the formula and replace the column name, but it didn't produce the right answer. Could you help me check the below screenshot? Thank you.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-04-07 at 3.08.04 PM.png" style="width: 567px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31932iA08FDBE16723799A/image-dimensions/567x128?v=v2" width="567" height="128" role="button" title="Screen Shot 2021-04-07 at 3.08.04 PM.png" alt="Screen Shot 2021-04-07 at 3.08.04 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 20:22:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/374977#M62471</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2021-04-07T20:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375020#M62474</link>
      <description>&lt;P&gt;The screen dump of the formula does not let me see if you are referencing the columns correctly.&amp;nbsp; That is, are you placing a ":" in front of the column names, but not in front of curgroup and value?&lt;/P&gt;
&lt;P&gt;What error messages are you getting?&lt;/P&gt;
&lt;P&gt;When you say that it is not working correctly, what does that mean?&amp;nbsp; Not getting the correct values, or is it not giving you any results?&lt;/P&gt;
&lt;P&gt;I have attached your sample data table with a column called Jim's Formula that has my formula applied to the data table.&amp;nbsp; This is so you can have a working version of the formula for comparison to what you are attempting to create.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 23:32:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375020#M62474</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-07T23:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375119#M62484</link>
      <description>Thank you Jim! I pasted your formula directly to my data and checked again- it worked on top ~7000 rows, but from that on it's all ".", not showing the first number that's not 10000000. When I entered the formula it did run for long time so I had to pressed esc to unfreeze jmp. is that causing this to happen? I totally have around 7000k rows.</description>
      <pubDate>Thu, 08 Apr 2021 14:34:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375119#M62484</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2021-04-08T14:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375165#M62491</link>
      <description>&lt;P&gt;That's a lot of rows. This formula may require less memory. &amp;nbsp;It assumes the first value ≠&amp;nbsp;10000000000 always is less than&amp;nbsp;10000000000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Col Min(:score, :group) == 10000000000,
    .,
    Col Min(
        :score[Col Min(Row(), :group, :score == 10000000000)],
        :group
    )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 15:14:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375165#M62491</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2021-04-08T15:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: find first element with condition in a column</title>
      <link>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375206#M62498</link>
      <description>&lt;P&gt;Here is a different approach to solving the problem.&amp;nbsp; This approach is a script.&amp;nbsp; It should be more efficient that the previous single formula column approach.&amp;nbsp; It first finds the first values, extracts them to a new table, and then uses the Update platform to merge the values back into the original data table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dt=current data table();

// Create a column that finds the first values
dt&amp;lt;&amp;lt;new column("theSelected",formula(If( :group != Lag( :group ),
	flag = 0
);
If( :score != 10000000000 &amp;amp; flag == 0,
	flag = 1;
	value = 1;
,
	value = .
);
value;));

// Select all of the rows that are marked as first values
dt&amp;lt;&amp;lt;select where(:theSelected==1);

// Create a subset of the marked rows
dtSel=dt&amp;lt;&amp;lt;subset(selected rows(1),columns({group,score}));

// Delete the marking column in the original data table
dt&amp;lt;&amp;lt;delete columns(theSelected);

// Change the name or the score column in the new data table 
// because when merged back into the original table it needs
// a different name
dtSel:Score &amp;lt;&amp;lt; set name("First Value");

// Merge the first found data back into the original table
dt &amp;lt;&amp;lt; Update(
	With( dtSel ),
	Match Columns( :group = :group )
);

// Delete the first selected data table
close(dtSel,nosave);

// Remove row selection from the original table
dt &amp;lt;&amp;lt; clear select;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Apr 2021 16:36:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/find-first-element-with-condition-in-a-column/m-p/375206#M62498</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-08T16:36:24Z</dc:date>
    </item>
  </channel>
</rss>

