<?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: Count number of unique items in column that meet some criteria in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962753#M110289</link>
    <description>&lt;P&gt;Column E would make more sense like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	New Column( "e",
		formula( 
			Write( "\!nE" || Char( Row() ) ); 
			As Constant( Write( "\!nE as constant " || Char( Row() ) ); a + b + c + d; ); 
		)
	)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Q variable is not needed and hides AsColumn's purpose in life.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Aug 2026 12:24:05 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2026-08-04T12:24:05Z</dc:date>
    <item>
      <title>Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961666#M110239</link>
      <description>&lt;P&gt;Suppose in "Big Class" I'd like a formula that counts the number of unique names of people at or less than the height of the person in the current row.&amp;nbsp; How can I do that?&lt;/P&gt;
&lt;P&gt;I have this:&lt;/P&gt;
&lt;P&gt;thisHeight = :height;&lt;BR /&gt;Col N Unique( :name, :height &amp;lt;= thisHeight );&lt;/P&gt;
&lt;P&gt;I realize the second parameter is the grouping parameter, and it's more intuitive to try to constrain what gets passed into the first parameter, but I haven't had any luck with anything I've tried to this point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2026 22:48:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961666#M110239</guid>
      <dc:creator>BHarris</dc:creator>
      <dc:date>2026-07-27T22:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961765#M110243</link>
      <description>&lt;P&gt;The closest built in function that comes to mind is &lt;STRONG&gt;Col Rank( :height, &amp;lt;&amp;lt;tie( "maximum" ) )&lt;/STRONG&gt;. The problem is: this counts the total number of &lt;U&gt;rows&lt;/U&gt; at or below thisHeight, not the number of &lt;U&gt;unique names&lt;/U&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Instead, you could try a custom formula, like this:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;thisHeight = :height; //store the current height value

// Build an associative array to collect unique names at or below thisHeight
aa = Associative Array();
For( i = 1, i &amp;lt;= N Rows(), i++,
    If( Column("height")[i] &amp;lt;= thisHeight, 
        aa[Column("name")[i]] = 1  // This only adds to the Associative Array if this is a new, unique name
    )
);

// The number of Items that have been added to the array = number of unique names
N Items( aa )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2026 10:41:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961765#M110243</guid>
      <dc:creator>christian-z</dc:creator>
      <dc:date>2026-07-28T10:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961794#M110249</link>
      <description>&lt;P&gt;Not sure if you can do it with Col functions as the new ones behave a bit differently than old ones.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;As Constant(n = :name &amp;lt;&amp;lt; get values);
curheight = :height;
r = Where(:height &amp;lt;= curheight);
N Items(Set Unique(n[r]));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2026 12:34:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961794#M110249</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-07-28T12:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961808#M110251</link>
      <description>&lt;P&gt;I tried something very close to this yesterday evening and it froze JMP.&amp;nbsp; I left it to run all night, and when I got in this morning the JMP data table window was blank, unresponsive, and Task Manager says the machine was only using one core and had 40+GB RAM free (so it didn't run out of RAM or take over the CPUs).&amp;nbsp; My table has nearly 400k rows, so I think this is maybe an O(N^2) kind of solution...&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2026 13:09:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961808#M110251</guid>
      <dc:creator>BHarris</dc:creator>
      <dc:date>2026-07-28T13:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961809#M110252</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp; &amp;nbsp;Re. my comment above, this also looks like a O(N^2) solution.&amp;nbsp; (Really sucks that a bad formula can block/crash the entire session, lost a chunk of my afternoon's work yesterday due to attempting a similar solution.)&lt;/P&gt;
&lt;P&gt;Sad that the new Col functions don't work the same, my question was perhaps overly simplistic, I need the grouping columns as well and I'm not sure how to implement them in this solution.&amp;nbsp; I'll probably just have to do this in python, which is sad because the column won't auto-update and python scripts can't be saved in the table yet.&lt;/P&gt;
&lt;P&gt;ps.&amp;nbsp; In my goal to learn a little bit from you at every interaction ;)&lt;/img&gt; -- why does this approach need the "As Constant()" function?&amp;nbsp; What would happen without it?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2026 13:23:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961809#M110252</guid>
      <dc:creator>BHarris</dc:creator>
      <dc:date>2026-07-28T13:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961810#M110253</link>
      <description>&lt;P&gt;If you need a formula, I'm not sure how well Python would work. As Constant() is there to prevent getting the list of names again and again on each row.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2026 13:43:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/961810#M110253</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-07-28T13:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962325#M110273</link>
      <description>&lt;P&gt;The python solution worked, and was pretty quick to implement/run, all things considered.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still hoping that Col N Unique() gets reworked for a future version to be similar to the others.&lt;/P&gt;
&lt;P&gt;I also kind-of wish there was a "JMP Formula Cookbook" somewhere that we could leverage/search.&amp;nbsp; I've actively been coding VBA, AppleScript, perl, python, and javascript (and little bits of C++) for all of my 33 years of my adult life, and JSL is by far the most difficult one of all of them to learn and understand.&amp;nbsp; I still don't understand why As Constant() would be necessary or what it even does.&amp;nbsp; I've read most of the Scripting Guide book, but it feels like&amp;nbsp;there needs to be another one somehow.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2026 16:22:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962325#M110273</guid>
      <dc:creator>BHarris</dc:creator>
      <dc:date>2026-07-31T16:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962398#M110277</link>
      <description>&lt;P&gt;You don't want to evaluate values which won't change on each row of the formula execution.&amp;nbsp;That is what As Constant() does, it makes JMP to evaluate that expression only once, on the first row.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/19.1/#page/jmp/programming-functions.shtml?os=win&amp;amp;source=application#ww5032467" target="_blank" rel="noopener"&gt;As Constant(expr)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1785561132878.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/111693i30412520277D0EE0/image-size/large?v=v2&amp;amp;px=999" role="button" title="jthi_0-1785561132878.png" alt="jthi_0-1785561132878.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I think you could basically replace it with (most likely not exactly the same, but quite close)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() == 1,
	n = :name &amp;lt;&amp;lt; get values;
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Aug 2026 05:15:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962398#M110277</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-08-01T05:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962659#M110283</link>
      <description>&lt;P&gt;At risk of taking this question down a rabbit hole, one more question --&lt;/P&gt;
&lt;P&gt;Do column formulas effectively get evaluated once, but with each expression evaluated in an array context?&lt;/P&gt;
&lt;P&gt;Or does the entire formula get re-executed once per row with Row() dictating which row is currently being evaluated?&lt;/P&gt;
&lt;P&gt;Or am I misunderstanding something more fundamental?&amp;nbsp; My mental model of what JMP is doing with formulas is bifurcated into incompatible pieces...&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2026 16:01:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962659#M110283</guid>
      <dc:creator>BHarris</dc:creator>
      <dc:date>2026-08-03T16:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962723#M110287</link>
      <description>&lt;P&gt;Someone who knows the internals of JMP can give better answer than my guess (&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;maybe). I consider them expressions (they are just JSL) which gets evaluated for each row, directly to the datatable, when needed. The when needed is determined by JMP unless I suppress the evaluation. There are some optimizations such as Col functions which evaluate (most of the time) only once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are some useful links from JMP Help but I can quickly only find this one:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/19.1/#page/jmp/calculator-functions.shtml" target="_blank" rel="noopener"&gt;Scripting Guide &amp;gt; Data Tables &amp;gt; Calculator Functions&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 04 Aug 2026 05:04:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962723#M110287</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-08-04T05:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962752#M110288</link>
      <description>&lt;P&gt;Here's a technique for exploring the rabbit hole:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled",
	Add Rows( 3 ),
	New Column( "a",
		Formula(Write( "\!nA" || Char( Row() ) );Row();),
		Set Selected
	),
	New Column( "b",
		Formula(Write( "\!nB" || Char( Row() ) );:c + :d + 100;)
	),
	New Column( "c",
		Formula(Write( "\!nC" || Char( Row() ) );:a + 1000;)
	),
	New Column( "d",
		Formula(Write( "\!nD" || Char( Row() ) );:a + 10000;)
	),
	new column( "e",
		formula(write("\!nE" || char(row())); asconstant(write("\!nE as constant "|| char(row())); Q=a+b+c+d); Q;)
	)
);

/*

A1 &amp;lt;&amp;lt; A must be done first, every other column depends on A
A2
A3
D1
D2
D3
C1
C2
C3
B1 &amp;lt;&amp;lt; B must be after C and D
B2
B3
E as constant 1 &amp;lt;&amp;lt; the constant is calculated before the first cell, but using row 1
E1 &amp;lt;&amp;lt; E must be last; the asconstant value uses all other columns
E2
E3

*/
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Craige_Hales_0-1785844389493.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/111954i91295F410D501DA2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Craige_Hales_0-1785844389493.png" alt="Craige_Hales_0-1785844389493.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The ; is a JSL operator that executes a series of statements and returns the last statement's value. That means a print/show/write statement can be prepended to a calculation to make a trace in the log.&lt;/P&gt;
&lt;P&gt;Above I learned the asconstant(...) is pulled out before the first row is calculated, but with row 1 as the current row.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;JMP also sorts through the columns to figure out which ones can evaluate first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2026 12:03:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962752#M110288</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2026-08-04T12:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of unique items in column that meet some criteria</title>
      <link>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962753#M110289</link>
      <description>&lt;P&gt;Column E would make more sense like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	New Column( "e",
		formula( 
			Write( "\!nE" || Char( Row() ) ); 
			As Constant( Write( "\!nE as constant " || Char( Row() ) ); a + b + c + d; ); 
		)
	)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Q variable is not needed and hides AsColumn's purpose in life.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2026 12:24:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-number-of-unique-items-in-column-that-meet-some-criteria/m-p/962753#M110289</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2026-08-04T12:24:05Z</dc:date>
    </item>
  </channel>
</rss>

