I have a script that calculates nonconformance rates for nonconformance codes and also creates control charts for each code over a user entered date range. The user can enter up to five individual codes and there are over 50 codes to pick from. There is a table created that has the total nonconforming quantity per code per date, the sum of the nonconforming quantities of all entered codes and the total quantity manufactured per day (NC Rate By Date Per Code - Original). Then I add to the table by iterating through a loop to add a column to calculate the nonconfcormance rate for each code and then a second to display the rate as a percentage (NC Rate By Date Per Code - Complete). Right now all the rate columns are ending up identical and as are the precentage columns though not the correct percentage version of the rate.
The loop is basically identical to one created at the very end of the script to summarize the nonconformance data over the entire date range (Overall NC Rate Per Code - Original, Overall NC Rate Per Code - Complete) which calculates correctly and I can't tell what's going wrong.
I attched screenshots of the metnioned tables and the script sections (codes = list of all entered codes as strings, SD and NR are table references)
If(NItems(codes)>=2,
For(c=2, c<=NItems(codes)+1, c++,
NR<<New Column("Code " || codes[c-1] || " NC Rate", Numeric, Continuous, Formula(Round((Column(c)[] / :Manufactured Qty), 4)));
col ref = (2*c) + NItems(codes);
NR<<New Column("Code " || codes[c-1] || " NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(col ref)[]));
);
NR<<New Column("Total Selected Codes NC Rate", Numeric, Continuous, Formula(Round(:Total Selected Codes NC Qty / :Manufactured Qty, 4)));
NR<<New Column("Total Selected Codes NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(NCol(NR)-1)[]));
);
If(NItems(codes)>=2,
For(c=2, c<=NItems(codes)+1, c++,
SD<<New Column("Code " || codes[c-1] || " NC Rate", Numeric, Continuous, Formula(Round((Column(c)[1] / :Manufactured Qty), 4)));
col ref = (2*c) + NItems(codes);
SD<<New Column("Code " || codes[c-1] || " NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(col ref)[1]));
);
SD<<New Column("Total Selected Codes NC Rate", Numeric, Continuous, Formula(Round((:Total Selected Codes NC Qty / :Manufactured Qty), 4)));
SD<<New Column("Total Selected Codes NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(NCol(SD)-1)[]));
);