<?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: creating formula using existing column names in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/486900#M73072</link>
    <description>&lt;P&gt;You have 2 issues going on here.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;When a formula is presented to a new column, it is not processed before being added as the formula.&amp;nbsp; Therefore, when you are specifying
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:Column(dt, colname)&lt;/CODE&gt;&lt;/PRE&gt;
JMP does not change it to the first numeric column name, then the second, etc.&amp;nbsp; The JSL author must use code that will expand the reference into the complete/ finished JSL statement before passing it to the Format element&lt;/LI&gt;
&lt;LI&gt;The column names in your data table, i.e. 1, 2, 3, 4 etc. will cause problems in JMP interpreting them, unless you specifically indicate they are to be interpreted as column names.&amp;nbsp; Therefore, you need to use the :"column name"n structure&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Below is a reworking of your code that produces the new columns you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
numcol = dt &amp;lt;&amp;lt; Get Column Names( Numeric );
charcol = dt &amp;lt;&amp;lt; Get Column Names( Character );


For( k = 1, k &amp;lt;= N Items( numcol ), k++,
	colname = Column( numcol[k] ) &amp;lt;&amp;lt; Get Name;

	Eval(
		Substitute(
				Expr(
					dt &amp;lt;&amp;lt; New Column( "site" || numcol[k],
						formula(
							If(
								:ID == "item5", (__colname__ * 0.5) / 20,
								:ID == "item8", (__colname__ * 0.8) / 20,
								__colname__ 
							)
						)
					)
				),
			Expr( __colname__ ), Parse( ":\!"" || colname || "\!"n")
		)
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 14 May 2022 03:08:46 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2022-05-14T03:08:46Z</dc:date>
    <item>
      <title>creating formula using existing column names</title>
      <link>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/486881#M73071</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
numcol=dt &amp;lt;&amp;lt; Get Column Names(Numeric);
charcol=dt &amp;lt;&amp;lt; Get Column Names( Character);


For( k = 1, k &amp;lt;= N Items( numcol ), k++,
colname=column(numcol[k]) &amp;lt;&amp;lt;Get Name;

dt &amp;lt;&amp;lt; New Column( "site"||numcol[k],
formula(If(
	:ID == "item5", (:Column( dt, colname)* 0.5) / 20,
	:ID == "item8", (:Column( dt, colname) * 0.8) / 20,
	:Column( dt, colname)
)
)
);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi JMP users,&lt;/P&gt;&lt;P&gt;I have a data table that I need to do some conversions on numeric columns based on predefined criteria.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting error "Expression does not fit available column types at row 1 in access or evaluation of 'Bad Argument' ".&lt;/P&gt;&lt;P&gt;Any idea on how to resolve this? Appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:59:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/486881#M73071</guid>
      <dc:creator>midori555</dc:creator>
      <dc:date>2023-06-09T16:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: creating formula using existing column names</title>
      <link>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/486900#M73072</link>
      <description>&lt;P&gt;You have 2 issues going on here.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;When a formula is presented to a new column, it is not processed before being added as the formula.&amp;nbsp; Therefore, when you are specifying
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:Column(dt, colname)&lt;/CODE&gt;&lt;/PRE&gt;
JMP does not change it to the first numeric column name, then the second, etc.&amp;nbsp; The JSL author must use code that will expand the reference into the complete/ finished JSL statement before passing it to the Format element&lt;/LI&gt;
&lt;LI&gt;The column names in your data table, i.e. 1, 2, 3, 4 etc. will cause problems in JMP interpreting them, unless you specifically indicate they are to be interpreted as column names.&amp;nbsp; Therefore, you need to use the :"column name"n structure&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Below is a reworking of your code that produces the new columns you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
numcol = dt &amp;lt;&amp;lt; Get Column Names( Numeric );
charcol = dt &amp;lt;&amp;lt; Get Column Names( Character );


For( k = 1, k &amp;lt;= N Items( numcol ), k++,
	colname = Column( numcol[k] ) &amp;lt;&amp;lt; Get Name;

	Eval(
		Substitute(
				Expr(
					dt &amp;lt;&amp;lt; New Column( "site" || numcol[k],
						formula(
							If(
								:ID == "item5", (__colname__ * 0.5) / 20,
								:ID == "item8", (__colname__ * 0.8) / 20,
								__colname__ 
							)
						)
					)
				),
			Expr( __colname__ ), Parse( ":\!"" || colname || "\!"n")
		)
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 May 2022 03:08:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/486900#M73072</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-05-14T03:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: creating formula using existing column names</title>
      <link>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/487211#M73103</link>
      <description>&lt;P&gt;Thanks Jim it works!&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:21:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-formula-using-existing-column-names/m-p/487211#M73103</guid>
      <dc:creator>midori555</dc:creator>
      <dc:date>2022-05-16T18:21:52Z</dc:date>
    </item>
  </channel>
</rss>

