<?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 Loop -  variable columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106382#M38997</link>
    <description>&lt;P&gt;I suspect that your pass/failed is not getting returned as the last calculated value.&amp;nbsp; The following adjustment may solve your issue.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = dt &amp;lt;&amp;lt; get column names;
For( i = 1, i &amp;lt;= N Items( col ), i++,
	c = "c" || Char( i );
	Eval( Parse( Eval Insert( "^c^= column(dt,i)&amp;lt;&amp;lt;get values" ) ) );
);

New Column( "Flag",
	Character,
	Nominal,
	Formula(
		For( i = 1, i &amp;lt; 3, i++,
			If( c2[i] &amp;gt; :LSL[i],
				x = "Pass",
				x = "Failed"
			)
		);
		x;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, you have a bigger issue. Your formula relys on having a memory variable called "c2" for it to work.&amp;nbsp; If you ever change, or delete the value of that variable, the formula will use the changed value to calculate the formula, or if it has been deleted, the formula will no longer work at all.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jan 2019 14:15:45 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2019-01-15T14:15:45Z</dc:date>
    <item>
      <title>Formula Loop -  variable columns</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106380#M38995</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem with the script.&lt;BR /&gt;I get an empty column when I try to use the loop.&lt;/P&gt;&lt;P&gt;When I don't use a loop, it's works.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = dt &amp;lt;&amp;lt; get column names;
For(i = 1, i &amp;lt;= N Items(col), i++,
    c = "c" || Char(i);
    Eval(Parse(Eval Insert("^c^= column(dt,i)&amp;lt;&amp;lt;get values"))));

&lt;BR /&gt;New Column( "Flag",&lt;BR /&gt; Character,&lt;BR /&gt; Nominal,&lt;BR /&gt; Formula(for(i=1,i&amp;lt;3,i++,&lt;BR /&gt; if(c2[i]&amp;gt;:LSL[i],"Pass","Failed"))));&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class="lia-message-subject lia-component-message-view-widget-subject"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 15 Jan 2019 13:33:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106380#M38995</guid>
      <dc:creator>Botzal</dc:creator>
      <dc:date>2019-01-15T13:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Loop -  variable columns</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106382#M38997</link>
      <description>&lt;P&gt;I suspect that your pass/failed is not getting returned as the last calculated value.&amp;nbsp; The following adjustment may solve your issue.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = dt &amp;lt;&amp;lt; get column names;
For( i = 1, i &amp;lt;= N Items( col ), i++,
	c = "c" || Char( i );
	Eval( Parse( Eval Insert( "^c^= column(dt,i)&amp;lt;&amp;lt;get values" ) ) );
);

New Column( "Flag",
	Character,
	Nominal,
	Formula(
		For( i = 1, i &amp;lt; 3, i++,
			If( c2[i] &amp;gt; :LSL[i],
				x = "Pass",
				x = "Failed"
			)
		);
		x;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, you have a bigger issue. Your formula relys on having a memory variable called "c2" for it to work.&amp;nbsp; If you ever change, or delete the value of that variable, the formula will use the changed value to calculate the formula, or if it has been deleted, the formula will no longer work at all.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 14:15:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106382#M38997</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-01-15T14:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Loop -  variable columns</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106393#M39000</link>
      <description>&lt;P&gt;Thx for your answer.&lt;/P&gt;&lt;P&gt;* According to your script, it's not working so well&amp;nbsp;&amp;nbsp;-&amp;nbsp;I get the same answer every row, because you are printing after the loop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* As for the big issue -&lt;BR /&gt;&amp;nbsp;What do you propose to do?&lt;BR /&gt;&amp;nbsp;I need to check that every row(to all columns) between the LSL and USL&amp;nbsp;- But the problem is, the name of the columns changes all the time.&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;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 982px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/15112i2896EB7826CB3972/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 15:15:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106393#M39000</guid>
      <dc:creator>Botzal</dc:creator>
      <dc:date>2019-01-15T15:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Loop -  variable columns</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106451#M39009</link>
      <description>&lt;P&gt;First thing I'd say is that this is an &lt;A href="http://xyproblem.info/" target="_self"&gt;XY Problem&lt;/A&gt;. But to answer the question of how do you make a flag check a dynamic number of columns, I would build the formula outside of the formula itself.&amp;nbsp;&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 = New Table( "Test",
	Add Rows( 5 ),
	Set Header Height( 46 ),
	New Column( "System",
		Character,
		"Nominal",
		Set Values( {"F_T_F_S", "F_T_F_R", "F_T_F_T", "F_T_F_U", "F_T_F_V"} )
	),
	New Column( "01/09/2019",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [500, 450, 900, 358, 500] )
	),
	New Column( "01/10/2019",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [666, 120, 280, 852, 456] )
	),
	New Column( "01/11/2019",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [520, 500, 450, 520, 520] )
	),
	New Column( "01/12/2019",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [450, 666, 120, 450, 450] )
	),
	New Column( "LSL",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [500, 800, 800, 0, 0] )
	),
	New Column( "USL",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [980, 1100, 1100, 3700, 3700] )
	)
);
//build the formula outside of the formula itself
ANDExpr = Expr(AND()); // we're going to throw all relavent columns into this AND Expression
for(i=2, i&amp;lt;=5, i++,
	col = Column(i);
	insert into(ANDExpr, 
		EvalExpr(:LSL &amp;lt; Expr(col)[] &amp;lt; :USL) // for each column check that it's between LSL &amp;amp; USL
	);
);
f = EvalExpr(
	if(Expr(nameexpr(ANDExpr)), 
		"Pass", 
		"Fail"
	)
);
show(nameexpr(f));
Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("Flag", formula(Expr(nameexpr(f)))) ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also do a list of names instead of numbers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 18:24:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106451#M39009</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-01-15T18:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Loop -  variable columns</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106577#M39033</link>
      <description>Great,&lt;BR /&gt;Thx for your support.&lt;BR /&gt;Next time I will provide full details and solutions I have already tried.&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Jan 2019 07:38:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-Loop-variable-columns/m-p/106577#M39033</guid>
      <dc:creator>Botzal</dc:creator>
      <dc:date>2019-01-16T07:38:37Z</dc:date>
    </item>
  </channel>
</rss>

