cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
Chris_Liu
Level II

Change formula

   As the attachments show, the formula of column ROW(3) is effective but just for one row.

   The formula of column "Used For loop " as below color shows, I know that formulas can't contain For loops, so remove the For loop parts and change ":Scan input[i]" to other expressions or other functions to Implement from ": Scan input[1]" to": Scan input[end row number]", then automatically updated based on each row of the "Scan input" column. Please help to correct it, thanks!

For(i = 1, i <= N Rows(), i++,
	If(Is Missing(:Scan input),
		"",
		If(Col Sum(:Blacklist == :Scan input[i]) > 0,
			"NG",
			"OK"
		)
	)
)
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Change formula

Collect all blacklist values to list/associative array and compare current rows value to that

As Constant(
	bl = :Blacklist << get values;
);
If(!IsMissing(:Scan input),
	If(Contains(bl, :Scan input),
		"NG"
	,
		"OK"
	);
,
	""
);

jthi_0-1739255658084.png

 

-Jarmo

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: Change formula

You stated that you can not have a For Loop in a formula.  The actual statement about For Loops in formulas is that there is not need to use a For Loop in a formula to loop through each row in a data table, because formulas are automatically applied to each row.  

But if there is a need for a For Loop to be run on each row, then it can certainly be used.

 

Here are 3 ways to write a formula that will do what I believe is your desired result

txnelson_0-1739250709205.png

 

If( Is Missing( :Scan input ),
	theResult = "",
	theResult = "OK";
	For( i = 1, i <= N Rows( Current Data Table() ), i++,
		If( :Blacklist == :Scan input[i],
			theResult = "NG";
			Break();
		)
	);
);
theResult;
If( Is Missing( :Scan input ),
	"",
	curBlacklist = :Blacklist;
	If( N Rows( Current Data Table() << get rows where( :Scan input == curBlacklist ) ) > 0,
		"NG",
		"OK"
	);
)
As Constant( Summarize( ScanList = by( :Scan input ) ) );
If( Is Missing( :Scan input ),
	"",
	If( N Rows( Loc( ScanList, :Blacklist ) ) > 0,
		"NG",
		"OK"
	)
);
Jim
Chris_Liu
Level II

Re: Change formula

Thanks! However, the correct result on rows 3 and 5 should show NG. It hasn't been solved yet.

Chris_Liu
Level II

Re: Change formula

Thanks! However, the correct result on rows 3 and 5 should show NG. It hasn't been solved yet.

txnelson
Super User

Re: Change formula

The formulas that I provided all look at the value of Black List for a given row, and then look through all of the rows for Scan Input to see if there is any row that has the same value.

I must have misinterpreted what you are trying to do.  I thought that was what your supplied JSL was trying to do.  Can you describe what your desired results are?

Jim
Chris_Liu
Level II

Re: Change formula

The results of all Blacklist columns are NG. The actual scenario is that the products produced by a fixture are already known to be NG. They need to be found out and scanned into the Scan input column with a barcode gun, and NG will be displayed as long as the value of the "Scan input" column is in any row of the Blacklist column. For example, row 1 is exactly equal so it shows NG, and row 3 is not exactly equal, but "X1" appears in row 1 of the Blacklist column, so need shows NG.

jthi
Super User

Re: Change formula

Collect all blacklist values to list/associative array and compare current rows value to that

As Constant(
	bl = :Blacklist << get values;
);
If(!IsMissing(:Scan input),
	If(Contains(bl, :Scan input),
		"NG"
	,
		"OK"
	);
,
	""
);

jthi_0-1739255658084.png

 

-Jarmo
jthi
Super User

Re: Change formula

How is "NG" or "OK" result to be determined (in words, not as a JSL)?

-Jarmo
Chris_Liu
Level II

Re: Change formula

The results of all Blacklist columns are NG. In no order, as long as the value of the "Scan input" column appears in any row of the Blacklist column, NG will be displayed. Using the formula makes it easy to find the defective product during the scanning process.

Recommended Articles