Hi,
Based on the expected output in your question, I think there is a slight mistake in your formula for "Defective Rate(%)" column if you only wanted "Rejected" rows from "Category" column to be ignored.
I never tried using For each row or Begin data update before, so I am not sure how to fix your current codes using those commands. However I have 2 alternative approaches on how you can achieve the same output.
1) Using IF command (faster approach):
dt=Current data table();
a = (dt<< New Column("DR", "Continuous", Formula(If(:Category == "Reject", "", Char(:Cell Qty / :Daily Total)))))<<get values;
dt << New Column("Defective Rate(%)", "Continuous", set values(a));
b = (dt<< New Column("Y", "Continuous", Formula(If(:Category == "Binned", Char(:Cell Qty / :Daily Total), ""))))<<get values;
dt << New Column("Yield", "Continuous", set values(b));
dt<<delete columns({"DR","Y"});
Since some columns are meant to be returned as empty columns (""), the created columns will automatically set themselves to character columns even though you have already defined them as numeric when you create the columns. Hence I've created extra dummy columns to serve the calculation purposes and set these values into new columns ("Defective Rate(%)" and " Yield") that you intend to create. In this way, you will be getting numeric columns.
2) Using Get rows where() and FOR loops:
dt=Current data table();
dt << New Column("Defective Rate(%)", "Continuous", numeric);
r1 = dt << get rows where(:Category!="Reject");
for (i=1, i<=nrows(r1), i++,
Column(dt, "Defective Rate(%)")[r1] = :Cell Qty[r1] / :Daily Total[r1]
);
dt << New Column("Yield", "Continuous", numeric);
r2 = dt << get rows where(:Category=="Binned");
for (i=1, i<=nrows(r2), i++,
Column(dt, "Yield")[r2] = :Cell Qty[r2] / :Daily Total[r2]
);
I believe this approach will be slower if your data set is huge since looping takes longer processing time.
Final Output:
Hope this helps!
Best Regards,
Val