<?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 column formula using a column name from a list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579805#M78706</link>
    <description>&lt;P&gt;Row 14 can be excluded. Can you share the code? I just wanted to refer and get an idea&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Dec 2022 13:21:51 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2022-12-10T13:21:51Z</dc:date>
    <item>
      <title>How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579314#M78658</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new column in the 2nd JMP table&amp;nbsp;&lt;SPAN&gt;with a formula that simply sums the Columns contain in the list (in the code I've assigned column name to &lt;STRONG&gt;binss.&lt;BR /&gt;For Ex: The list contains Column names "39","41","43". I want to create a new Column in the Soft Bin Summary table with addition of all these in the formula&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I can't figure out what I'm doing wrong in going from the list {""} of columns to the reference to the columns.&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code that I've tried&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Clear Globals();

dt = Data Table( "Untitled 910" );
dt2 = Data Table( "Soft Bin Summary" );

Try( For Each Row( :Yield SummaryBins = Word( 1, :Yield SummaryBins, "[]" ) ) );
grouplist = dt:Yield SummaryBins &amp;lt;&amp;lt; get values;

For( i = N Items( grouplist ), i &amp;gt;= 1, i--,
	If( grouplist[i] == "",
		Remove From( grouplist, i, 1 ), 

	));
binss = {}; /// list contaiting bin value
For( i = 1, i &amp;lt;= N Items( grouplist ), i++, 

	If( Contains( grouplist[i], " " ), 

		Insert Into( binss, grouplist[i] )
	)
);

adad = Words( binss[1], " " );
F = Eval Expr( Sum( Expr( adad ) ) );

/// Something doesn't seem to right in the below loop

For( i = 1, i &amp;lt;= N Items( binss ), i++, 	
dt2 &amp;lt;&amp;lt; New Column( binss[i], "Numeric", "Continuous", Format( "Percent", 12, 2 ), Formula( Name Expr( F ) ) );); &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jack&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:04:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579314#M78658</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-06-09T16:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579397#M78661</link>
      <description>&lt;P&gt;You were running into an issue where the rows with multiple column names were not being handled correctly.&amp;nbsp; Here is my attempt at solving your issue.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1670599704974.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/48091i5BFD667B9D3E794E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1670599704974.png" alt="txnelson_0-1670599704974.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Clear Globals();

dt = Data Table( "Untitled 910" );
dt2 = Data Table( "Soft Bin Summary" );

current data table(dt);

// Build execution string
sumString = "";
for each row(
	if(:Yield SummaryBins != "",
		i=1;
		while(word(i,:Yield SummaryBins,"[] ") !=  "",
			sumString = sumString || ", :\!"" || word(i,:Yield SummaryBins,"[] ") || "\!"n";
			i++;
		)
	)
);
// Remove first comma
sumString = substr(sumString, 1);

// Execute new column string
eval(parse("dt2&amp;lt;&amp;lt;new column(\!"Sum Column\!", formula(sum(" || sumString || ")));"));

// Add the format for the column
dt2:Sum Column &amp;lt;&amp;lt; format("Percent", 7, 2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2022 15:29:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579397#M78661</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-12-09T15:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579419#M78663</link>
      <description>&lt;P&gt;Thanks Jim.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code works. I want to create separate columns for each group.&lt;/P&gt;&lt;P&gt;For ex: In the below case, There are two groups Opens and Shorts which contains respective column name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have two different columns with a formula that sums the respective values&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column 1 (Sum of Column (39, 41, 43)) and Column 2&amp;nbsp;(Sum of Column (38, 40, 42)) in the Summary table&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jacksmith12_0-1670600829273.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/48093i32254C15266DE7D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jacksmith12_0-1670600829273.png" alt="Jacksmith12_0-1670600829273.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 15:50:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579419#M78663</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2022-12-09T15:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579435#M78664</link>
      <description>&lt;P&gt;It is a matter of just expanding on the code I provided.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Clear Globals();

dt = Data Table( "Untitled 910" );
dt2 = Data Table( "Soft Bin Summary" );

Current Data Table( dt );

// Build execution string
openString = shortsString = "";
For Each Row(
	If( :Yield SummaryBins != "",
		If( :Yield SummaryLabel == "Opens",
			i = 1;
			While( Word( i, :Yield SummaryBins, "[] " ) != "",
				openString = openString || ", :\!"" || Word( i, :Yield SummaryBins, "[] " ) || "\!"n";
				i++;
			);
		);
		If( :Yield SummaryLabel == "Shorts",
			i = 1;
			While( Word( i, :Yield SummaryBins, "[] " ) != "",
				shortsString = shortsString || ", :\!"" || Word( i, :Yield SummaryBins, "[] " ) || "\!"n";
				i++;
			);
		);
	)
);
// Remove first comma
openString = Substr( openString, 1 );
shortsString = Substr( shortsString, 1 );

// Execute new column strings
Eval( Parse( "dt2&amp;lt;&amp;lt;new column(\!"Open Column\!", formula(sum(" || openString || ")));" ) );
Eval( Parse( "dt2&amp;lt;&amp;lt;new column(\!"Shorts Column\!", formula(sum(" || shortsString || ")));" ) );

// Add the format for the column
dt2:Open Column &amp;lt;&amp;lt; Format( "Percent", 7, 2 );
dt2:Shorts Column &amp;lt;&amp;lt; Format( "Percent", 7, 2 );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please take the time to study the code provided and to respond back with additional questions when you do not understand how the code is working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 16:08:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579435#M78664</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-12-09T16:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579453#M78667</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;Thank you. Much appreciated.&lt;BR /&gt;Can it be done dynamically? I've cases where there are more than 2 groups. Writing separate string execution function would be tedious.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I've attached a reference table below&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>Tue, 03 Jan 2023 16:03:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579453#M78667</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-01-03T16:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579478#M78671</link>
      <description>Of course it can....what are the rules?</description>
      <pubDate>Fri, 09 Dec 2022 17:22:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579478#M78671</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-12-09T17:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579485#M78672</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;The rules are similar to previous example.&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Create each separate Column group with a formula that sums the respective bins. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want to create a Column in the Soft Bin Summary table with addition of all Column name bins in the formula.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For ex: Create IDD Currents group Column with formula (Sum( Column ("52", "42","49") )),&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Create Open group Column with formula&amp;nbsp;&lt;STRONG&gt;(Sum( Column ("39", "41","43") ))&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;and like wise for the remaining label groups in the Yield Summary label column&lt;/STRONG&gt;&lt;/STRONG&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>Tue, 03 Jan 2023 16:03:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579485#M78672</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-01-03T16:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579660#M78690</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;, could you advice?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 22:42:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579660#M78690</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2022-12-09T22:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579705#M78697</link>
      <description>&lt;P&gt;My read of your description is that the rule you have is to create a new column for each row in the Condition Table that has a value in the Yield SummaryLabel column.&lt;/P&gt;
&lt;P&gt;So I suggest that you read through each row in the Conditions Table, and when you find a row with a value in the Yield SummaryLabel column, you create the new column.&lt;/P&gt;
&lt;P&gt;There is one case where you have an issue.&amp;nbsp; Row 14 which has SYL_Yield specified, it has a value of 1 for Yield SummaryBins.&amp;nbsp; There is not a column called "1".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1670635432240.png" style="width: 902px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/48138iEE8DE04AE96E134A/image-dimensions/902x300?v=v2" width="902" height="300" role="button" title="txnelson_0-1670635432240.png" alt="txnelson_0-1670635432240.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 01:25:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579705#M78697</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-12-10T01:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579805#M78706</link>
      <description>&lt;P&gt;Row 14 can be excluded. Can you share the code? I just wanted to refer and get an idea&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 13:21:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579805#M78706</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2022-12-10T13:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create column formula using a column name from a list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579816#M78709</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Data Table( "Condition table" );
dt2 = Data Table( "Soft Bin Summary" );

Current Data Table( dt );

// Rule: Create a new Summary Column for each row in the Condition Table
// that has a value in the Yield SummaryLabel column
For( i = 1, i &amp;lt;= N Rows( dt ), i++,
	If( dt:Yield SummaryLabel[i] != "",
		theString = "";
		k = 1;
		While( Word( k, dt:Yield SummaryBins[i], "[] " ) != "",
			theString = theString || ", :\!"" || Word(
				k,
				dt:Yield SummaryBins[i],
				"[] "
			) || "\!"n";
			k++;
		);
		theString = Substr( theString, 1 );
		Eval(
			Parse(
				"dt2&amp;lt;&amp;lt;new column(\!"" || dt:Yield SummaryLabel[i] ||
				"\!", formula(sum(" || theString ||
				")),Format( \!"Percent\!", 7, 2 ));"
			)
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only compensation that Community members get for helping other members, is the satisfaction that comes from the members they have helped becoming more self-sufficient.&amp;nbsp; Cutting and pasting of someone else's working code is not a good way to become self-sufficient.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 16:03:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-column-formula-using-a-column-name-from-a-list/m-p/579816#M78709</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-12-10T16:03:32Z</dc:date>
    </item>
  </channel>
</rss>

