cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Abby_Collins14
Level III

Fill column once per group without repeating values with JSL

Hi!

So I have the below data table.  The individual test results are in the "test result" column and indicate if the respective y passes test a,b, and c. The "overall result" column indicates a "pass" if 2 or more of the tests (a,b,c) pass.

 

I was able compute the overall result with a formula, but what I would like to do is get a list that says the result once per Y variable-- i.e. overall result = "pass, fail, pass" like the ideal overall result has. Any ideas??

Abby_Collins14_0-1711058765076.png

code for dt: 

dt = New Table( "example",
	Add Rows( 0 ),
	New Column( "Y", character ),
	New Column( "test",character ),
	New Column( "test result",character )
	
)

:Y << set values( {var1,var1,var1,var2,var2,var2,var3,var3,var3});

:test << set values( {a,b,c,a,b,c,a,b,c});

:test result<< set values( {pass,pass,fail,fail,pass,fail,pass,pass,pass});

new column("overall result",Formula(if(col sum(test result=="pass",Y)>=2, "Pass", "Fail")));
1 ACCEPTED SOLUTION

Accepted Solutions
mmarchandTSI
Level V

Re: Fill column once per group without repeating values with JSL

Just need a small change to your formula.

 

New Column( "overall result",
	Formula(
		If(
			Col Cumulative Sum( 1, :Y ) > 1, "",
			Col Sum( test result == "pass", :Y ) >= 2, "Pass",
			"Fail"
		)
	)
);

mmarchandTSI_0-1711060120886.png

 

View solution in original post

2 REPLIES 2
mmarchandTSI
Level V

Re: Fill column once per group without repeating values with JSL

Just need a small change to your formula.

 

New Column( "overall result",
	Formula(
		If(
			Col Cumulative Sum( 1, :Y ) > 1, "",
			Col Sum( test result == "pass", :Y ) >= 2, "Pass",
			"Fail"
		)
	)
);

mmarchandTSI_0-1711060120886.png

 

jthi
Super User

Re: Fill column once per group without repeating values with JSL

Additional option (I usually do these type of "shifts" using Row() == Col Min(Row()) or Row() == Col Max(Row())).

Names Default To Here(1);

dt = New Table("example 4",
	Add Rows(9),
	Compress File When Saved(1),
	New Column("Y", Character, "Nominal", Set Values({"var1", "var1", "var1", "var2", "var2", "var2", "var3", "var3", "var3"})),
	New Column("test", Character, "Nominal", Set Values({"a", "b", "c", "a", "b", "c", "a", "b", "c"})),
	New Column("test result", Character, "Nominal", Set Values({"pass", "pass", "fail", "fail", "pass", "fail", "pass", "pass", "pass"}))
);

dt << New Column("Res",	Character, Nominal, Formula(
	If(Row() != Col Min(Row(), :Y),
		"" // not first row fir Y group
	, Col Sum(:test result == "pass", :Y) >= 2,
		"pass"
	, // else
		"fail"
	)
));
-Jarmo