<?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: Formula columns generated through script do not have the correct source column name in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/411487#M66103</link>
    <description>&lt;P&gt;That works! Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 20 Aug 2021 06:31:12 GMT</pubDate>
    <dc:creator>mvanderaa1</dc:creator>
    <dc:date>2021-08-20T06:31:12Z</dc:date>
    <item>
      <title>Formula columns generated through script do not have the correct source column name</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/410429#M66016</link>
      <description>&lt;P&gt;Hi everyone, I have a script that creates new numerical columns for any columns that has very small values (i.e. transform a column that has unit meters into mm or µm for better readability).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seemed to be working fine; the columns were generated without issue. But then I got some issues later on when joining with other tables, suddenly the columns showed no data anymore. When I check the formula in the new columns I see that instead of the name of the source column, it has a colnames[i] reference from the loop in the script (see screenshot).&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 = Current Data Table();
colnames = dt &amp;lt;&amp;lt; get column names( numeric, string );
For( i = 1, i &amp;lt;= N Items( colnames ), i++, 
	If( (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))&amp;lt;1e-4 &amp;amp; (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))&amp;gt;0,	
		If( !Contains( colnames, colnames[i] || "_µm"),
		dt &amp;lt;&amp;lt; New Column( colnames[i] || "_µm", Formula( As Column( colnames[i] ) * 1e6 ) ) )
	,
	If( (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))&amp;lt;1e-1 &amp;amp; (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))&amp;gt;1e-4,
		If( !Contains( colnames, colnames[i] || "mm"),
		dt&amp;lt;&amp;lt;New Column(colnames[i]||"_mm",Formula(As Column(colnames[i])*1e3)))
	)
	),	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:54:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/410429#M66016</guid>
      <dc:creator>mvanderaa1</dc:creator>
      <dc:date>2023-06-09T19:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Formula columns generated through script do not have the correct source column name</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/410448#M66020</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/29478"&gt;@mvanderaa1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a pretty common problem, can you try one of the options listed at the link below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My go-to is the top one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Eval Expr
For( i = 1, i &amp;lt;= N Items(cols), i++,
       Eval( Eval Expr(
              dt &amp;lt;&amp;lt; New Column( 
                    "2 * " || Char( cols[i] ),
                    Numeric,
                    "Continuous",
                    Formula( As Column( Expr( Char( cols[i] ) ) ) * 2)
              )
       ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 12:09:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/410448#M66020</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-08-17T12:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Formula columns generated through script do not have the correct source column name</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/411487#M66103</link>
      <description>&lt;P&gt;That works! Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 06:31:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-columns-generated-through-script-do-not-have-the-correct/m-p/411487#M66103</guid>
      <dc:creator>mvanderaa1</dc:creator>
      <dc:date>2021-08-20T06:31:12Z</dc:date>
    </item>
  </channel>
</rss>

