It is cool that custom functions can be used as well as part of custom formulas in Formula Editor.
With the Transform Category command, the
New Custom Function( "myNamespace", "Add Ten", Function( {x, y = 10}, x + y ), << Transform Category( "Custom" ));from https://www.jmp.com/support/help/en/16.2/#page/jmp/create-custom-functions-transforms-and-formats.shtml
will show up in the right click New Formula Column Menu - and produce a column with formula

I just started with @txnelson 's approach
https://community.jmp.com/t5/Discussions/Formula-for-Number-of-Unique-Categories-in-Column/m-p/55284/highlight/true#M31262
to generate a column to Count Unique values - but instead of typing the formula, I wanted to use a Custom Function.
The manually generated Formula Column works, but the column that uses the Custom Function count unique doesn't.
It fails with the error message

Seems that x in the by() expression is not replaced with the column name.
So, use Eval(Substitute() to fix the issue?
... but how?
With
Eval(Substitute(Expr(Summarize( values = by( _col_ ) )),Expr(_col_),Name Expr(x) ));
I get

- because in a Column Formula :x is treated as :x[row()]. Argh ...
Along this line, I start to wonder why does this work:

[NB: the red zig-zag line just tells the user that print in a column formula is not a good idea]
why does Jmp know that it has to send get values to the COLUMN :sex and and not to :sex[row()].
And why does it actually return :sex[row()] in the second line - and not the column :sex ?
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Add Custom Functions(
New Custom Function(
"custom",
"count unique",
Function( {x},
As Constant( Summarize( values = by( x ) ) );
N Items( values );
),
<<TRANSFORM category=""></TRANSFORM>
Hello @hogi ,
I'm not sure if this is a smart approach, but the following script works. I used eval insert function. I hope it helps.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Add Custom Functions(
New Custom Function(
"custom",
"count unique",
Function( {x},
Eval( Parse( Eval Insert( "As Constant( Summarize( values = by( :^x^ ) ) )" ) ) );
N Items( values );
),
<<TRANSFORM category=""></TRANSFORM>hm, unfortunately, it doesn't work:

produces the error message:

So, the same as like with
Substitute (..., Expr(_col_),Name Expr(x))
I guess it's because a function call to make it work has to be
custom:count unique( "sex" )
instead if
custom:count unique( :sex )
I just found an earlier (2018) version of the same question:
Column reference in custom function
The quite definite reply from Jmp Support TS-00063463
