<?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: How to create an average column with JSL based on random columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/970172#M110518</link>
    <description>&lt;P&gt;While from a theoretical and as-built-mechanics stand point you are probably absolutely right....it is not how the user interface behaves. I select columns from the table and drag those onto the mean() operator and it calculates. However in scripting I cannot select columns, but I have to select string objects (that correspond to column names) and then tell JSL to interpret those as column references, which I can then inject into the mean operator. Wouldn't it be an easy fix to augment the jsl operators to treat Column("Name") as column objects which can be indexed to the row? That would make much more intuitive sense and mirror user interface behavior and therefor user thinking. AS you pointed out, there is a lot of user confusion about this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And to Jarmo's points: the error messaging in the formula editor is in need of some clarity and consistency upgrades. Again: do note that the preview shows correct evaluation while the formula does not evaluate when using the Column("Name") syntax.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Sep 2026 12:16:41 GMT</pubDate>
    <dc:creator>pauldeen</dc:creator>
    <dc:date>2026-09-10T12:16:41Z</dc:date>
    <item>
      <title>How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968140#M110445</link>
      <description>&lt;P&gt;I want to make a column list based on some selection criteria. Column names would not be known in advance. Then I use that column list to make a formula column that takes the mean (or sd or number) of those columns.&lt;/P&gt;
&lt;P&gt;Simple example script which takes all numeric columns:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Cars.jmp" );
ColList = {};
For(i=1, i&amp;lt;=NCols(), i++,
	If(Column(i)&amp;lt;&amp;lt;GetDataType=="Numeric", InsertInto(ColList, Column(i)))
);
MeanExpr = NameExpr(Mean());
For(i=1, i&amp;lt;=NItems(ColList), i++,
	InsertInto(MeanExpr, ColList[i])
);
Eval(
	EvalExpr(
		dt &amp;lt;&amp;lt; NewColumn("Average of numerics",
			Formula(
				Expr(NameExpr(MeanExpr))
			)
		)
	)
);

MeanExpr2 = NameExpr(Mean());
For(i=1, i&amp;lt;=NItems(ColList), i++,
	InsertInto(MeanExpr2, NameExpr(AsColumn(ColList[i])))
);
Eval(
	EvalExpr(
		dt &amp;lt;&amp;lt; NewColumn("Average of numerics 2",
			Formula(
				Expr(NameExpr(MeanExpr2))
			)
		)
	)
);
&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;Notice that ColList is a valid list of columns. When this gets inserted into the first column formula, the preview in the formula editor shows correct evaluation but the column remains empty. Apparently we need to insert scalars, list or matrix into the Mean() function (but the preview will work regardless).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pauldeen_0-1788272598908.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/115064i3C11FFA7C1D866DE/image-size/medium?v=v2&amp;amp;px=400" alt="pauldeen_0-1788272598908.png" title="pauldeen_0-1788272598908.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The second formula column adds a AsColumn() around the column reference...which is a bit counter intuitive as it is already a column. But now it creates a list, scalar or matrix and the mean() formula will work.&lt;/P&gt;
&lt;P&gt;It feels like i'm making this way to complicated. Is there a simpler way to procedurally generate such a summary column?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2026 14:40:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968140#M110445</guid>
      <dc:creator>pauldeen</dc:creator>
      <dc:date>2026-09-01T14:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968192#M110446</link>
      <description>&lt;P&gt;Usually in simple cases like this I use Substitute to replace list with some other expression&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Cars.jmp");
collist = dt &amp;lt;&amp;lt; Get Column Names("Numeric", "String");

colrefs = Transform Each({colname}, collist,
	Name Expr(As Column(dt, colname))
);

mexpr = Substitute(colrefs, Expr(List), Expr(Mean));

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("AVG", Numeric, Continuous, Formula(
		Expr(Name Expr(mexpr))
	));	
));

Write();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Sep 2026 16:12:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968192#M110446</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-09-01T16:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968633#M110449</link>
      <description>&lt;P&gt;Thanks but this still is an advanced level solution for a simple problem. Still interested to see if somebody comes up with a simpler way to add column references to a column formula.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2026 13:38:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968633#M110449</guid>
      <dc:creator>pauldeen</dc:creator>
      <dc:date>2026-09-03T13:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968636#M110451</link>
      <description>&lt;P&gt;Assume we have column named "TEST" in table dt. There are differences between the "basic"&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Column(dt, "TEST")&lt;/LI&gt;
&lt;LI&gt;AsColumn(dt, "TEST")&lt;/LI&gt;
&lt;LI&gt;"TEST"&lt;/LI&gt;
&lt;LI&gt;Name Expr(As Column(dt, "TEST"))&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Cars.jmp");
Row() = 0; // default row value

col = "Size";

Show(col);
Show(Column(dt, col));
Show(AsColumn(dt, col));
Show(Name Expr(AsColumn(dt, col)));
Show(dt:col);
Show(AsName(col));

Write("\!N\!N");

Row() = 1;
Show(Column(dt, col)[Row()]);
Show(AsColumn(dt, col));
Show(Name Expr(AsColumn(dt, col)));
Show(dt:col);
Show(AsName(col));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type of solution are you looking for? You do not add column references to formulas unless you use [] or [Row()] with the reference.&amp;nbsp;If you are getting your columns as references (or strings), generally you will have to convert them into "column accesses" to use them in formulas.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2026 14:05:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/968636#M110451</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-09-03T14:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/969733#M110500</link>
      <description>&lt;P&gt;I submitted a bug report to JMP.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bug is that the column formula does not accept Column(“name”) arguments, but instead they have to be wrapped in an As Column() expression first. When using the visual formula editor, you do drop columns in the argument fields, so JSL should reflect the same behavior. Adding this to JSL would greatly simplify creation of column formula's from JSL.&lt;/P&gt;
&lt;P&gt;Apparently, the preview window in the formula editor does interpret this correctly as it shows a preview.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2026 14:44:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/969733#M110500</guid>
      <dc:creator>pauldeen</dc:creator>
      <dc:date>2026-09-08T14:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/969766#M110501</link>
      <description>&lt;P&gt;Column() and AsColumn()/:colname are not same and should not be used in similar manner.&lt;/P&gt;
&lt;P&gt;In my opinion, the bug here here is with the formula editor and how it shows the formulas when built using JSL. It does miss incorrect formulas (like in this case) and it doesn't show error messages when it should.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1788881236165.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116066i2ECD603B28826845/image-size/medium?v=v2&amp;amp;px=400" alt="jthi_1-1788881236165.png" title="jthi_1-1788881236165.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1788881243139.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116067iCABE58CE258C1347/image-size/large?v=v2&amp;amp;px=999" alt="jthi_2-1788881243139.png" title="jthi_2-1788881243139.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_4-1788881274171.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116069i5F9439FAAC6B477E/image-size/large?v=v2&amp;amp;px=999" alt="jthi_4-1788881274171.png" title="jthi_4-1788881274171.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case it should be showing this in the column properties&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_7-1788882167381.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116079iCB3B7F01E078A8CA/image-size/medium?v=v2&amp;amp;px=400" alt="jthi_7-1788882167381.png" title="jthi_7-1788882167381.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and this in formula editor&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_6-1788882151203.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116076i6A340C1EEC5E6AF7/image-size/medium?v=v2&amp;amp;px=400" alt="jthi_6-1788882151203.png" title="jthi_6-1788882151203.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And if you try to apply it error like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_5-1788882131736.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116075iC7915B114C043321/image-size/medium?v=v2&amp;amp;px=400" alt="jthi_5-1788882131736.png" title="jthi_5-1788882131736.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;
&lt;P&gt;If you fix it to be Column()[] it does show correctly and it will return correct results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1788880964367.png"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/116065iC3C45D413534C60B/image-size/medium?v=v2&amp;amp;px=400" alt="jthi_0-1788880964367.png" title="jthi_0-1788880964367.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But it is up to JMP developers to decide how they think this should behave&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2026 15:43:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/969766#M110501</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-09-08T15:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/969825#M110504</link>
      <description>&lt;P&gt;Jarmo makes good points and provided an alternative solution of using Column("name")[].&amp;nbsp; As mentioned by Jarmo, using Column("name")[] doesn't look as nice in the Formula Editor.&amp;nbsp; My solution below does not go into that option, but it explains why this is confusing for a lot of users.&amp;nbsp; It does repeat a lot of what Jarmo has already posted, but since I already had it typed...&lt;/P&gt;
&lt;DIV&gt;Actually what the OP script illustrates is not a bug.&amp;nbsp; This is expected behavior, and it illustrates a confusion that a lot of users have with referencing columns and how column formula evaluation works.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;At the crux of the confusion is understanding the difference between Column("name") syntax and :name syntax.&amp;nbsp; Both are legitimate ways to refer to columns in some circumstances, but what they return is different.&amp;nbsp; Specifically, Column("name") returns a reference to a column object while :name returns the value in the name column on the current row.&amp;nbsp; By the way, :name is the operator form of the function As Column("name").&amp;nbsp; In other words, those are exactly the same thing.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Consider the following example script to illustrate.&amp;nbsp; This script assumes you have the Cars.jmp data table open and current in your JMP session.&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open( "$SAMPLE_DATA/Cars.jmp" );

// sending messages to a column; either syntax works
Column(dt, "Year") &amp;lt;&amp;lt; Set Property("Range Check", LELE(87, 97));
dt:Head IC &amp;lt;&amp;lt; Set Property("Spec Limits", {LSL( 150 ), Show Limits( 1 )});

// Return values

// returns a column object reference shown as Column( "Year" ) in log
Column(dt, "Year"); // returns Column( "Year" )

// returns value in Year column on the current row.  
// Since current row is 0 (the default invalid row number), returns missing (.)
:Year; // returns .

// Set the current row to the first row
Row() = 1;
:Year; // returns 87&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV&gt;With that information in mind, it should be clear that JMP cannot calculate the mean of a set of column references.&amp;nbsp; This is why the first column formula does not evaluate successfully.&amp;nbsp; The Mean() function needs values - which are provided in the second column formula.&amp;nbsp; As a data table evaluates the column formulas, it sets the current row to 1 then evaluates the expression stored in the Formula property.&amp;nbsp; It places the return value in the column's cell in the current row.&amp;nbsp; Then it sets the current row to the next value and repeats.&amp;nbsp; These steps are repeated until the formula is evaluated for the last row.&amp;nbsp; Consequently, the syntax of the column formula must be one that can evaluate for each row of the data table.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;To me, there is one unexpected result from your example script.&amp;nbsp; Namely that the syntax As Column(Column("name")) evaluates the same as As Column("name").&amp;nbsp; I expected that it would throw an error, but JMP accepts it and interprets the intent correctly.&amp;nbsp; That is the (sometimes) advantage of a scripting language over a formal programming language.&amp;nbsp; However, I would not recommend employing this syntax as it may fail in the future.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I think the best way to accomplish the goal given the example script is to drop the first approach at a column formula and use the second approach.&amp;nbsp; The additional change is to define ColList to be a list of column names instead of column references.&amp;nbsp; Here is a modified version of the OP script example that should be robust.&lt;/DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Cars.jmp" );
ColList = {};
For( i = 1, i &amp;lt;= N Cols(), i++,
	If( Column( i ) &amp;lt;&amp;lt; GetDataType == "Numeric",
		Insert Into( ColList, &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;Column( i ) &amp;lt;&amp;lt; Get Name&lt;/STRONG&gt;&lt;/FONT&gt; )
	)
);
 
MeanExpr2 = Name Expr( Mean() );
For( i = 1, i &amp;lt;= N Items( ColList ), i++,
	Insert Into( MeanExpr2, Name Expr( As Column( ColList[i] ) ) )
);
Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "Average of numerics 2", Formula( Expr( Name Expr( MeanExpr2 ) ) ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Sep 2026 21:45:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/969825#M110504</guid>
      <dc:creator>Jasean</dc:creator>
      <dc:date>2026-09-08T21:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an average column with JSL based on random columns</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/970172#M110518</link>
      <description>&lt;P&gt;While from a theoretical and as-built-mechanics stand point you are probably absolutely right....it is not how the user interface behaves. I select columns from the table and drag those onto the mean() operator and it calculates. However in scripting I cannot select columns, but I have to select string objects (that correspond to column names) and then tell JSL to interpret those as column references, which I can then inject into the mean operator. Wouldn't it be an easy fix to augment the jsl operators to treat Column("Name") as column objects which can be indexed to the row? That would make much more intuitive sense and mirror user interface behavior and therefor user thinking. AS you pointed out, there is a lot of user confusion about this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And to Jarmo's points: the error messaging in the formula editor is in need of some clarity and consistency upgrades. Again: do note that the preview shows correct evaluation while the formula does not evaluate when using the Column("Name") syntax.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2026 12:16:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-an-average-column-with-JSL-based-on-random-columns/m-p/970172#M110518</guid>
      <dc:creator>pauldeen</dc:creator>
      <dc:date>2026-09-10T12:16:41Z</dc:date>
    </item>
  </channel>
</rss>

