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)
//NC Rate By Date Per Code Section
//Calculate NC rates and percentages for entered codes if two or more codes are entered
If(NItems(codes)>=2,
For(c=2, c<=NItems(codes)+1, c++,
//Add NC Rate column for each code
NR<<New Column("Code " || codes[c-1] || " NC Rate", Numeric, Continuous, Formula(Round((Column(c)[] / :Manufactured Qty), 4)));
//Establish reference column number for NC Rate Percentage columns
col ref = (2*c) + NItems(codes);
//Add NC Rate Percentage column for each code
NR<<New Column("Code " || codes[c-1] || " NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(col ref)[]));
); //Closes NC rates and percentages For Loop
//Calculate NC rates and percentages for All Selected Codes
//Add :Total Selected Codes NC Rate
NR<<New Column("Total Selected Codes NC Rate", Numeric, Continuous, Formula(Round(:Total Selected Codes NC Qty / :Manufactured Qty, 4)));
//Add :Total Selected Codes NC Rate Percentage
NR<<New Column("Total Selected Codes NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(NCol(NR)-1)[]));
); //Closes Two or More Codes If Loop
//Overall NC Rate Per Code Section
//Calculate NC rates and percentages for entered codes if two or more codes are entered
If(NItems(codes)>=2,
For(c=2, c<=NItems(codes)+1, c++,
//Add NC Rate column for each code
SD<<New Column("Code " || codes[c-1] || " NC Rate", Numeric, Continuous, Formula(Round((Column(c)[1] / :Manufactured Qty), 4)));
//Establish reference column number for NC Rate Percentage columns
col ref = (2*c) + NItems(codes);
//Add NC Rate Percentage column for each code
SD<<New Column("Code " || codes[c-1] || " NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(col ref)[1]));
); //Closes NC rates and percentages For Loop
//Calculate NC rates and percentages for All Selected Codes
//Add :Total Selected Codes NC Rate
SD<<New Column("Total Selected Codes NC Rate", Numeric, Continuous, Formula(Round((:Total Selected Codes NC Qty / :Manufactured Qty), 4)));
//Add :Total Selected Codes NC Rate Percentage
SD<<New Column("Total Selected Codes NC Rate Percentage", Numeric, Continuous, Format("Percent", 12, 2), Formula(Column(NCol(SD)-1)[]));
); //Closes Two or More Codes If Loop