<?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: Column Formula for summary value of group based on values in 2 other columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270602#M52673</link>
    <description>&lt;P&gt;Here is a formula that works with your Example data table.&amp;nbsp; It has not been tested beyond that, so you may need to make some adjustments&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = New Table( "Example",
	Add Rows( 9 ),
	New Column( "Group", Character, "Nominal", Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C"} ) ),
	New Column( "Time", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 8, 1, 2, 6, 1, 3, 7] ) ),
	New Column( "Score",
		Character,
		"Nominal",
		Set Values( {"Pass", "Fail", "Pass", "Pass", "Pass", "Pass", "Pass", "Fail", "Fail"} )
	)
);

dt &amp;lt;&amp;lt; New Column( "First Time Failed",
	character,
	formula(
		If( Row() == 1,
			dt = Current Data Table();
			check = :Score;
			If( :Group == :Group[2],
				Failed = Char( Col Max( :Time, :Group ), Failed = :Score )
			);
		,
			If( :Group == Lag( :Group ),
				If( :Score == "Fail",
					check = "Fail"
				);
				Failed = Char( Col Max( :Time, :Group ) );
			,
				If( check == "Pass",
					lagGroup = Lag( :Group );
					:First Time Failed[dt &amp;lt;&amp;lt; get rows where( :Group == lagGroup )] = "Pass";
					Failed = Char( Col Max( :Time, :Group ) );
				);
				check = :Score;
			)
		);
		failed;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Jun 2020 22:29:32 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2020-06-03T22:29:32Z</dc:date>
    <item>
      <title>Column Formula for summary value of group based on values in 2 other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270588#M52667</link>
      <description>&lt;P&gt;Hi everyone -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for a column formula that would return the following desired column below.&amp;nbsp; For simplicity in this post each group has 3 rows, but the dataset I currently have has groups with varying numbers of rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Group&lt;/TD&gt;&lt;TD&gt;Time&lt;/TD&gt;&lt;TD&gt;Score&lt;/TD&gt;&lt;TD&gt;First Time Failed (Desired Column)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;Fail&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Pass&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Fail&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;Fail&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:14:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270588#M52667</guid>
      <dc:creator>user8421</dc:creator>
      <dc:date>2023-06-10T23:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Column Formula for summary value of group based on values in 2 other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270602#M52673</link>
      <description>&lt;P&gt;Here is a formula that works with your Example data table.&amp;nbsp; It has not been tested beyond that, so you may need to make some adjustments&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = New Table( "Example",
	Add Rows( 9 ),
	New Column( "Group", Character, "Nominal", Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C"} ) ),
	New Column( "Time", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 8, 1, 2, 6, 1, 3, 7] ) ),
	New Column( "Score",
		Character,
		"Nominal",
		Set Values( {"Pass", "Fail", "Pass", "Pass", "Pass", "Pass", "Pass", "Fail", "Fail"} )
	)
);

dt &amp;lt;&amp;lt; New Column( "First Time Failed",
	character,
	formula(
		If( Row() == 1,
			dt = Current Data Table();
			check = :Score;
			If( :Group == :Group[2],
				Failed = Char( Col Max( :Time, :Group ), Failed = :Score )
			);
		,
			If( :Group == Lag( :Group ),
				If( :Score == "Fail",
					check = "Fail"
				);
				Failed = Char( Col Max( :Time, :Group ) );
			,
				If( check == "Pass",
					lagGroup = Lag( :Group );
					:First Time Failed[dt &amp;lt;&amp;lt; get rows where( :Group == lagGroup )] = "Pass";
					Failed = Char( Col Max( :Time, :Group ) );
				);
				check = :Score;
			)
		);
		failed;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 22:29:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270602#M52673</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-06-03T22:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Column Formula for summary value of group based on values in 2 other columns</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270854#M52721</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/17028"&gt;@user8421&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is just a fun alternative that uses data table formulas. It will work for unequal Group sizes and if the table is not sorted.&lt;/P&gt;
&lt;P&gt;The logic is to find the minimum row number for Fails in each Group. &lt;STRONG&gt;Col Minimum(... , By)&lt;/STRONG&gt;&amp;nbsp;is the key. Column statistic functions using the By option are very useful, but often overlooked functions.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 759px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24389iF6106490EC6A6C96/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formula for&amp;nbsp; column "Row First Failed"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 628px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24390i95B6C7D22CE3D835/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Formula for column "Time First Failed". Note if the syntax seems strange, the right-hand formula is Time, then select &lt;STRONG&gt;Subscript&lt;/STRONG&gt; from the &lt;STRONG&gt;Row&lt;/STRONG&gt; functions and drag column 4, "Row First Failed"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 527px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24391i757D453B4A3C6DB5/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 00:08:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Formula-for-summary-value-of-group-based-on-values-in-2/m-p/270854#M52721</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2020-06-05T00:08:35Z</dc:date>
    </item>
  </channel>
</rss>

