<?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: Get Rows that satisfy a condition within a column formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/656629#M84566</link>
    <description>&lt;P&gt;Very cool trick to use conditions as &lt;STRONG&gt;Group By&lt;/STRONG&gt; options :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Important to note:&lt;BR /&gt;With the suggested code, each condition&lt;/P&gt;&lt;P&gt;1) :height &amp;lt;=60&lt;/P&gt;&lt;P&gt;2) :height &amp;gt; 60)&lt;/P&gt;&lt;P&gt;gets it's own result.&lt;/P&gt;&lt;P&gt;There is another variant where the condition is used to restrict the aggregation to &lt;STRONG&gt;one&lt;/STRONG&gt; subset - and the result is written to all rows of the respective group. Like in te last column of this table:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1688759525464.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/54491i493C4B29F1E38E85/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1688759525464.png" alt="hogi_0-1688759525464.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;One option to get there:&lt;BR /&gt;Use Tables/Summary with a Data Filter (new in Jmp 17) and merge the values back to the main table:&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt &amp;lt;&amp;lt; New Column("CondSum",Numeric,Continuous,Formula(Col Sum( :weight, :age, :height &amp;gt; 60 )));

dtSum= dt &amp;lt;&amp;lt; Summary(
	Local Data Filter(
		Conditional,
		Add Filter( columns( :height ), Where( :height &amp;gt; 60 ) )
	),
	Group( :age ),
	Sum( :weight )
);



dt &amp;lt;&amp;lt; Update(
	With( dtSum ),
	Match Columns( :age = :age ),
	Add Columns from Update Table( :"Sum(weight)"n ),
	Replace Columns in Main Table( None )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;&lt;BR /&gt;Other approaches (with a variety of speeds) are discussed in&amp;nbsp;&amp;nbsp;&lt;LI-MESSAGE title="How do I use the Col Maximum Formula with a &amp;quot;where&amp;quot; condition." uid="34840" url="https://community.jmp.com/t5/Discussions/How-do-I-use-the-Col-Maximum-Formula-with-a-quot-where-quot/m-p/34840#U34840" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2023 20:34:17 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2023-07-07T20:34:17Z</dc:date>
    <item>
      <title>Get Rows that satisfy a condition within a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/49386#M28084</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Probably an easy question - but looking for some help over this. Is there a way to get rows that match a condition within a column formula ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;In the e.g.&amp;nbsp; shown below, one should be able to acheive&amp;nbsp; the grouped sum of a given group. If I wanted to add a condition on top of this , let us say on :height should be &amp;gt; 60 , how can I achieve that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt &amp;lt;&amp;lt; New Column("CondSum",Numeric,Continuous,Formula(Col Sum(:weight,:age)));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Outside a column formula , I believe that is easy and can achieve it. However, I would like to implement this through a column formula, if possible.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 17:10:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/49386#M28084</guid>
      <dc:creator>uday_guntupalli</dc:creator>
      <dc:date>2018-01-08T17:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get Rows that satisfy a condition within a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/49397#M28095</link>
      <description>&lt;P&gt;Hi Uday,&lt;/P&gt;&lt;P&gt;You can actually just type the condition as the&amp;nbsp;next argument.&lt;/P&gt;&lt;PRE&gt;Col Sum( :weight, :age, :height &amp;gt; 60 )&lt;/PRE&gt;&lt;P&gt;It may not look right at first in this Big Class example because the sum is the same for the 12 year olds below and above 60 inches.&amp;nbsp; They just happen to be the same sums.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 21:25:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/49397#M28095</guid>
      <dc:creator>cwillden</dc:creator>
      <dc:date>2018-01-08T21:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Get Rows that satisfy a condition within a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/414548#M66367</link>
      <description>&lt;P&gt;Hi, putting a comparison in as the byVar argument is a nice idea:&lt;/P&gt;&lt;PRE&gt;Col Sum( :weight, :age, :height &amp;gt;= 60 )&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; I am interested in putting a comparison in the byVar argument that is comparing it to the current row:&lt;/P&gt;&lt;PRE&gt;myheight = :height;&lt;BR /&gt;Col Sum( :weight, :age, :height &amp;gt;= myheight )&lt;/PRE&gt;&lt;P&gt;This does not work as expected:&amp;nbsp; the calculation shows a confusing set of numbers,&amp;nbsp; and then they all change to "1" if I change someone's height.&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Just for a better frame of reference, in my actual table, I am trying to count rows where the date in colA is greater than the datevalue in colA and where the date in colB is less then the datevalue in colB.)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 15:01:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/414548#M66367</guid>
      <dc:creator>mann</dc:creator>
      <dc:date>2021-09-01T15:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get Rows that satisfy a condition within a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/414578#M66369</link>
      <description>&lt;P&gt;So I'm guessing it has something to do with&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;The result is cached internally so that multiple evaluations will be efficient&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can't say for sure though.&amp;nbsp; If you just use an intermediate column it seems to work fine.&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 = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt &amp;lt;&amp;lt; New COlumn("Conditional", Formula(
	myheight = :height;
	:height &amp;gt;= myheight; // should always be 1
	//:height &amp;gt;= .5*weight // this might be a better example
));

dt &amp;lt;&amp;lt; New Column("CondSum",Numeric,Continuous,Formula(
	Col Sum( :weight, :age, :Conditional );
));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 15:23:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/414578#M66369</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2021-09-01T15:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Get Rows that satisfy a condition within a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/414580#M66370</link>
      <description>&lt;P&gt;The formula appears to only being evaluated when the Age column changes.&amp;nbsp; However, the formula below appears to get you what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myheight = :height;
myage = :age;
Sum( :weight[Current Data Table() &amp;lt;&amp;lt; get rows where( :age == myage &amp;amp; :height &amp;gt;= myheight )] );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 15:34:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/414580#M66370</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-09-01T15:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get Rows that satisfy a condition within a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/656629#M84566</link>
      <description>&lt;P&gt;Very cool trick to use conditions as &lt;STRONG&gt;Group By&lt;/STRONG&gt; options :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Important to note:&lt;BR /&gt;With the suggested code, each condition&lt;/P&gt;&lt;P&gt;1) :height &amp;lt;=60&lt;/P&gt;&lt;P&gt;2) :height &amp;gt; 60)&lt;/P&gt;&lt;P&gt;gets it's own result.&lt;/P&gt;&lt;P&gt;There is another variant where the condition is used to restrict the aggregation to &lt;STRONG&gt;one&lt;/STRONG&gt; subset - and the result is written to all rows of the respective group. Like in te last column of this table:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1688759525464.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/54491i493C4B29F1E38E85/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1688759525464.png" alt="hogi_0-1688759525464.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;One option to get there:&lt;BR /&gt;Use Tables/Summary with a Data Filter (new in Jmp 17) and merge the values back to the main table:&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt &amp;lt;&amp;lt; New Column("CondSum",Numeric,Continuous,Formula(Col Sum( :weight, :age, :height &amp;gt; 60 )));

dtSum= dt &amp;lt;&amp;lt; Summary(
	Local Data Filter(
		Conditional,
		Add Filter( columns( :height ), Where( :height &amp;gt; 60 ) )
	),
	Group( :age ),
	Sum( :weight )
);



dt &amp;lt;&amp;lt; Update(
	With( dtSum ),
	Match Columns( :age = :age ),
	Add Columns from Update Table( :"Sum(weight)"n ),
	Replace Columns in Main Table( None )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;&lt;BR /&gt;Other approaches (with a variety of speeds) are discussed in&amp;nbsp;&amp;nbsp;&lt;LI-MESSAGE title="How do I use the Col Maximum Formula with a &amp;quot;where&amp;quot; condition." uid="34840" url="https://community.jmp.com/t5/Discussions/How-do-I-use-the-Col-Maximum-Formula-with-a-quot-where-quot/m-p/34840#U34840" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 20:34:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Get-Rows-that-satisfy-a-condition-within-a-column-formula/m-p/656629#M84566</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-07-07T20:34:17Z</dc:date>
    </item>
  </channel>
</rss>

