<?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 How to dynamically assign X or Y variables in Graph Builder using JSL based on conditions? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880452#M104418</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="256" data-end="273"&gt;Hi JMP Community,&lt;/P&gt;
&lt;P data-start="275" data-end="539"&gt;I'm trying to build a dynamic &lt;CODE data-start="305" data-end="320"&gt;Graph Builder&lt;/CODE&gt; report in JSL where the list of X variables is determined by certain conditions (e.g., flags like &lt;CODE data-start="419" data-end="432"&gt;includeSite&lt;/CODE&gt;, &lt;CODE data-start="434" data-end="445"&gt;includeWW&lt;/CODE&gt;, etc.). The goal is to flexibly add or remove columns from the X-axis based on runtime logic.&lt;/P&gt;
&lt;P data-start="541" data-end="588"&gt;I’ve tried several approaches, including using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="overflow-visible!" data-start="589" data-end="686"&gt;X( :ColumnName )&lt;BR /&gt;X( Column("ColumnName") )&lt;BR /&gt;Expr( X(...) )&lt;BR /&gt;Substitute(...) and Eval(...)&lt;/PRE&gt;
&lt;P data-start="688" data-end="733"&gt;However, I consistently run into errors like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="overflow-visible!" data-start="734" data-end="819"&gt;Name Unresolved: X in access or evaluation of 'X'&lt;BR /&gt;Bad Argument( Column(...) )&lt;/PRE&gt;
&lt;P data-start="821" data-end="875"&gt;What I'm looking for is a reliable and correct way to:&lt;/P&gt;
&lt;UL data-start="876" data-end="1037"&gt;
&lt;LI data-start="876" data-end="923"&gt;
&lt;P data-start="878" data-end="923"&gt;Dynamically define a list of X-axis variables&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="924" data-end="954"&gt;
&lt;P data-start="926" data-end="954"&gt;Pass them to &lt;CODE data-start="939" data-end="954"&gt;Graph Builder&lt;/CODE&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="955" data-end="1037"&gt;
&lt;P data-start="957" data-end="1037"&gt;Avoid hardcoding the number of X variables or having to repeat the builder logic&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P data-start="1039" data-end="1078"&gt;Here’s a simplified version of my goal:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;xVars = {};
If( includeSite, Insert Into( xVars, :Site ) );
If( includeWW, Insert Into( xVars, :WW ) );
// add remaining fixed columns...

Graph Builder(
    Variables(
        // &amp;lt;- How can I inject xVars here properly?
        Y( :Measurement )
    ),
    Elements(
        Points( Y( :Measurement ) )
    )
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P data-start="1404" data-end="1590"&gt;I want to avoid generating multiple separate graph blocks depending on each condition. Is there a supported or recommended way to dynamically build up the &lt;CODE data-start="1559" data-end="1564"&gt;X()&lt;/CODE&gt; list for &lt;CODE data-start="1574" data-end="1589"&gt;Graph Builder&lt;/CODE&gt;?&lt;/P&gt;
&lt;P data-start="1592" data-end="1610"&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jun 2025 23:10:59 GMT</pubDate>
    <dc:creator>RA899</dc:creator>
    <dc:date>2025-06-18T23:10:59Z</dc:date>
    <item>
      <title>How to dynamically assign X or Y variables in Graph Builder using JSL based on conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880452#M104418</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="256" data-end="273"&gt;Hi JMP Community,&lt;/P&gt;
&lt;P data-start="275" data-end="539"&gt;I'm trying to build a dynamic &lt;CODE data-start="305" data-end="320"&gt;Graph Builder&lt;/CODE&gt; report in JSL where the list of X variables is determined by certain conditions (e.g., flags like &lt;CODE data-start="419" data-end="432"&gt;includeSite&lt;/CODE&gt;, &lt;CODE data-start="434" data-end="445"&gt;includeWW&lt;/CODE&gt;, etc.). The goal is to flexibly add or remove columns from the X-axis based on runtime logic.&lt;/P&gt;
&lt;P data-start="541" data-end="588"&gt;I’ve tried several approaches, including using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="overflow-visible!" data-start="589" data-end="686"&gt;X( :ColumnName )&lt;BR /&gt;X( Column("ColumnName") )&lt;BR /&gt;Expr( X(...) )&lt;BR /&gt;Substitute(...) and Eval(...)&lt;/PRE&gt;
&lt;P data-start="688" data-end="733"&gt;However, I consistently run into errors like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="overflow-visible!" data-start="734" data-end="819"&gt;Name Unresolved: X in access or evaluation of 'X'&lt;BR /&gt;Bad Argument( Column(...) )&lt;/PRE&gt;
&lt;P data-start="821" data-end="875"&gt;What I'm looking for is a reliable and correct way to:&lt;/P&gt;
&lt;UL data-start="876" data-end="1037"&gt;
&lt;LI data-start="876" data-end="923"&gt;
&lt;P data-start="878" data-end="923"&gt;Dynamically define a list of X-axis variables&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="924" data-end="954"&gt;
&lt;P data-start="926" data-end="954"&gt;Pass them to &lt;CODE data-start="939" data-end="954"&gt;Graph Builder&lt;/CODE&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="955" data-end="1037"&gt;
&lt;P data-start="957" data-end="1037"&gt;Avoid hardcoding the number of X variables or having to repeat the builder logic&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P data-start="1039" data-end="1078"&gt;Here’s a simplified version of my goal:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;xVars = {};
If( includeSite, Insert Into( xVars, :Site ) );
If( includeWW, Insert Into( xVars, :WW ) );
// add remaining fixed columns...

Graph Builder(
    Variables(
        // &amp;lt;- How can I inject xVars here properly?
        Y( :Measurement )
    ),
    Elements(
        Points( Y( :Measurement ) )
    )
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P data-start="1404" data-end="1590"&gt;I want to avoid generating multiple separate graph blocks depending on each condition. Is there a supported or recommended way to dynamically build up the &lt;CODE data-start="1559" data-end="1564"&gt;X()&lt;/CODE&gt; list for &lt;CODE data-start="1574" data-end="1589"&gt;Graph Builder&lt;/CODE&gt;?&lt;/P&gt;
&lt;P data-start="1592" data-end="1610"&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 23:10:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880452#M104418</guid>
      <dc:creator>RA899</dc:creator>
      <dc:date>2025-06-18T23:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically assign X or Y variables in Graph Builder using JSL based on conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880469#M104420</link>
      <description>&lt;P&gt;You could try first by using &amp;lt;&amp;lt; Add Variable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = Graph Builder(Variables(X(:age), Y(:weight)), Elements(Points(X, Y), Smoother(X, Y)));
Wait(0.5);
gb &amp;lt;&amp;lt; Add Variable({:height, Role("Y")});&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't work you might have to build X as expression and then evaluate it to graph builder&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2025 04:00:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880469#M104420</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-06-19T04:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically assign X or Y variables in Graph Builder using JSL based on conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880709#M104444</link>
      <description>&lt;P&gt;Using built-in functions - like&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;suggests - is a great way to handle such topics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to follow the original idea of &lt;LI-MESSAGE title="Writing JSL code dynamically" uid="820931" url="https://community.jmp.com/t5/JMPer-Cable/Writing-JSL-code-dynamically/m-p/820931#U820931" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;by defining and combining blocks of JSL code (="expressions"), please have a look at &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/1643"&gt;@Jasean&lt;/a&gt;&amp;nbsp;'s blog post&amp;nbsp;&lt;SPAN&gt;☝.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; &lt;BR /&gt;With&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Expr( X(...) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;you are close,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Substitute&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;Eval&lt;/FONT&gt; are other parts of the framework.&lt;BR /&gt;Maybe the most important function:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Name Expr()&lt;/FONT&gt;. It can be used to access the &lt;STRONG&gt;&lt;EM&gt;expression&lt;/EM&gt; &lt;/STRONG&gt;which is stored in a variable (=&lt;EM&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/EM&gt;) without evaluating it, e.g. via&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;y= Expr(X( "ColumnName") );
Name Expr(y);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;you will get&amp;nbsp;&lt;CODE class=" language-jsl"&gt;X( "ColumnName") &lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;instead of&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1750436611652.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/77117iD6E9C38B05786463/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1750436611652.png" alt="hogi_0-1750436611652.png" /&gt;&lt;/span&gt;&lt;BR /&gt;[without the Name Expr(), JMP tries to evaluate the expression - and will fail to understand - as &lt;FONT face="courier new,courier"&gt;X()&lt;/FONT&gt; is not defined]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Other resources on expression handling:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Expression-Handling-in-JMP-Tips-and-Trapdoors/m-p/747728/highlight/true#M92777" target="_blank" rel="noopener"&gt;Expression Handling in JMP: Tips and Trapdoors - JMP User Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680045#U680045" target="_blank" rel="noopener"&gt;Scripters Club, Session 9: Advanced JSL&lt;/A&gt;&lt;BR /&gt;&lt;LI-MESSAGE title="Expression Handling Functions: Part I - Unraveling the Expr(), NameExpr(), Eval(), ... Conundrum" uid="28963" url="https://community.jmp.com/t5/JMPer-Cable/Expression-Handling-Functions-Part-I-Unraveling-the-Expr/m-p/28963#U28963" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jun 2025 16:26:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880709#M104444</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-06-20T16:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically assign X or Y variables in Graph Builder using JSL based on conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880710#M104445</link>
      <description>&lt;P&gt;So, with the help of &lt;FONT face="courier new,courier"&gt;Expr()&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;Eval()&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;Substitute()&lt;/FONT&gt;, AND &lt;FONT face="courier new,courier"&gt;Name Expr()&lt;/FONT&gt;,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

xVars = Expr(X);
Insert Into( xVars, Expr(:age) );

Eval(Substitute(Expr(Graph Builder(
    Variables(
        __xVars__,
        Y( :height )
    )
    )
), Expr(__xVars__) , Name Expr(xVars)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jun 2025 16:33:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880710#M104445</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-06-20T16:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically assign X or Y variables in Graph Builder using JSL based on conditions?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880711#M104446</link>
      <description>&lt;P&gt;Instead of &lt;FONT face="courier new,courier"&gt;Substitute()&lt;/FONT&gt;, I prefer using &lt;FONT face="courier new,courier"&gt;Eval Expr()&lt;/FONT&gt; - which works like&amp;nbsp;&lt;BR /&gt;&lt;EM&gt;"search for &lt;FONT face="courier new,courier"&gt;Expr()&lt;/FONT&gt; and evaluate the content before you evaluate the whole thing":&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

xVars = Expr( X );
Insert Into( xVars, Expr( :age ) );

Eval(
	Eval Expr(
		Graph Builder(
			Variables( Expr( Name Expr( xVars ) ), Y( :height ) )
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;So, JMP has to find:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1750437462089.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/77118i210EE2B61BDC729A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1750437462089.png" alt="hogi_1-1750437462089.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and evaluate it. Please note the &lt;FONT face="courier new,courier"&gt;Name Expr()&lt;/FONT&gt;. As discussed in the previous post, this ensures that JMP only looks up the content of &lt;FONT face="courier new,courier"&gt;xVars&lt;/FONT&gt; and does not evaluate it. After retrieving it and inserting the block into the main block, the whole thing gets evaluated via the enclosing&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_2-1750437551646.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/77119i71EEC38B16865B02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_2-1750437551646.png" alt="hogi_2-1750437551646.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;An nice trick to check what's going on: omit the enclosing &lt;FONT face="courier new,courier"&gt;Eval()&lt;/FONT&gt; and look at the log.&lt;BR /&gt;Then JMP will print the "pre-cooked" expression in the log - without evaluating it. This allows the user to look at the final expression an scan for errors:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_3-1750437854722.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/77120iA5C5EDE692A28C69/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_3-1750437854722.png" alt="hogi_3-1750437854722.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If everything is as expected, simply add the &lt;FONT face="courier new,courier"&gt;Eval()&lt;/FONT&gt; to evaluate the expression.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jun 2025 16:47:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-dynamically-assign-X-or-Y-variables-in-Graph-Builder/m-p/880711#M104446</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-06-20T16:47:17Z</dc:date>
    </item>
  </channel>
</rss>

