<?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: Custom Function - how to reference the column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/694523#M87960</link>
    <description>&lt;P&gt;I just found an earlier (2018) version of the same question:&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="Column reference in custom function" uid="53291" url="https://community.jmp.com/t5/Discussions/Column-reference-in-custom-function/m-p/53291#U53291" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 04 Nov 2023 20:50:51 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2023-11-04T20:50:51Z</dc:date>
    <item>
      <title>Custom Function - how to reference the column</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/691701#M87746</link>
      <description>&lt;P&gt;It is cool that custom functions can be used as well as part of custom formulas in Formula Editor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the Transform Category command, the&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Custom Function( "myNamespace", "Add Ten", Function( {x, y = 10}, x + y ),  &amp;lt;&amp;lt; Transform Category( "Custom" ));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;from&amp;nbsp;&lt;A href="https://www.jmp.com/support/help/en/16.2/#page/jmp/create-custom-functions-transforms-and-formats.shtml" target="_blank" rel="noopener"&gt;https://www.jmp.com/support/help/en/16.2/#page/jmp/create-custom-functions-transforms-and-formats.shtml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;will show up in the right click New Formula Column Menu - and produce a column with formula&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1698521852106.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58075i8B5A304878782604/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1698521852106.png" alt="hogi_0-1698521852106.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just started with&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;'s approach&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Formula-for-Number-of-Unique-Categories-in-Column/m-p/55284/highlight/true#M31262" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/Formula-for-Number-of-Unique-Categories-in-Column/m-p/55284/highlight/true#M31262&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;to generate a column to&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Count Unique&lt;/FONT&gt;&amp;nbsp;values - but instead of typing the formula, I wanted to use a Custom Function.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The manually generated Formula Column works, but the column that uses the Custom Function &lt;FONT face="courier new,courier"&gt;count unique&lt;/FONT&gt; doesn't.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It fails with the error message&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1698522649974.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58076i5A85A802BE62D1D7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1698522649974.png" alt="hogi_1-1698522649974.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Seems that x in the &lt;FONT face="courier new,courier"&gt;by()&lt;/FONT&gt; expression is not replaced with the column name.&lt;/P&gt;&lt;P&gt;So, use &lt;FONT face="courier new,courier"&gt;Eval(Substitute()&lt;/FONT&gt;&amp;nbsp;to fix the issue?&lt;BR /&gt;... but how?&lt;/P&gt;&lt;P&gt;With&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(Substitute(Expr(Summarize( values = by( _col_ ) )),Expr(_col_),Name Expr(x) ));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_3-1698523534416.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58078i25195EEB1B52AC0F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_3-1698523534416.png" alt="hogi_3-1698523534416.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;- because in a Column Formula :x is treated as :x[row()]. Argh ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Along this line, I start to wonder why does this work:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_2-1698523113734.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58077i8B6E834F98FFA194/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_2-1698523113734.png" alt="hogi_2-1698523113734.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#999999"&gt;[NB: the red zig-zag line just tells the user that &lt;FONT face="courier new,courier" color="#000000"&gt;&lt;STRONG&gt;print&lt;/STRONG&gt; &lt;/FONT&gt;in a column formula is not a good idea]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;why does Jmp know that it has to send &lt;FONT face="courier new,courier"&gt;get values&lt;/FONT&gt; to the COLUMN&amp;nbsp;&lt;FONT face="courier new,courier"&gt;:sex&lt;/FONT&gt; and and not to &lt;FONT face="courier new,courier"&gt;:sex[row()].&lt;BR /&gt;&lt;/FONT&gt;And why does it actually return &lt;FONT face="courier new,courier"&gt;:sex[row()]&lt;/FONT&gt; in the second line - and not the column &lt;FONT face="courier new,courier"&gt;:sex&lt;/FONT&gt; ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&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 );
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 );
		),
		&amp;lt;&amp;lt;Transform Category( "Custom" ),
		&amp;lt;&amp;lt;Description( "count unique values" )
	)
);

New Column( "functionColumn",
	Formula(
		As Constant( Summarize( values = by( :sex ) ) );
		N Items( values );
	)
); //works

New Column( "customFunctionColumn", Formula( custom:count unique( :sex ) ) );&amp;nbsp;//doesn't&amp;nbsp;work&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Oct 2023 22:20:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/691701#M87746</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-10-29T22:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function - how to reference the column</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/693328#M87865</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I'm not sure if this is a smart approach, but the following script works. I used eval insert function. I hope it helps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 );
		),
		&amp;lt;&amp;lt;Transform Category( "Custom" ),
		&amp;lt;&amp;lt;Description( "count unique values" )
	)
);

New Column( "customFunctionColumn", Formula( custom:count unique( "sex" ) ) ); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 04:59:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/693328#M87865</guid>
      <dc:creator>yuichi_katsumur</dc:creator>
      <dc:date>2023-11-02T04:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function - how to reference the column</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/693757#M87912</link>
      <description>&lt;P&gt;hm, unfortunately, it doesn't work:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1698956749394.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58274i5015CE946A3585AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1698956749394.png" alt="hogi_1-1698956749394.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;produces the error message:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1698956713087.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58273i01FABA771185D418/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1698956713087.png" alt="hogi_0-1698956713087.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the same as like with&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Substitute (..., Expr(_col_),Name Expr(x))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess it's because a function call to make it work has to be&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;custom:count unique( "sex" )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;instead if&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;custom:count unique( :sex )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 20:30:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/693757#M87912</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-11-02T20:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function - how to reference the column</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/694523#M87960</link>
      <description>&lt;P&gt;I just found an earlier (2018) version of the same question:&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="Column reference in custom function" uid="53291" url="https://community.jmp.com/t5/Discussions/Column-reference-in-custom-function/m-p/53291#U53291" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Nov 2023 20:50:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/694523#M87960</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-11-04T20:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function - how to reference the column</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/694929#M88009</link>
      <description>&lt;P&gt;The quite definite reply from Jmp Support TS-00063463&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="hogi_1-1699302157298.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/58389iBEBBBDB825F6CEA3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1699302157298.png" alt="hogi_1-1699302157298.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2023 20:23:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Function-how-to-reference-the-column/m-p/694929#M88009</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-11-06T20:23:06Z</dc:date>
    </item>
  </channel>
</rss>

