根据用户输入搜索正确的范围
Searching the right range based on user input
出于愚蠢的原因,我们需要将我们的 1-4 评分系统转换为 1-100 等级。
我的主要问题是,是否有比我正在做的 better/quicker/more 更有效的方法?下面的 B3 点差sheet 展示了我的方法。
我的目标是,教师可以输入他们教了多少标准以及学生达到了什么标准,sheet 会自动查看正确的换算表来拉分。
因此,如果老师教标准达到 4,而孩子得到 4,那就是 100。如果老师教 2,孩子得到 2,那仍然是 100。而如果老师教 4,而孩子得了 2,只有 78。
在B3你可以看到我要去的方向。一长串带有 vlookup 的 ifs。正如你所看到的,我需要为每项任务的每一种可能性做这件事。它似乎 就像可以告诉计算机做的事情,因为它一遍又一遍地重复,只有微小的变化。
谢谢!
我已经在 Google Apps 脚本中完成了答案,因为它更容易直接实施。
这是示例数据。
这是示例输出。
我直接将转换后的成绩放在每项作业的分数下方。 (如果需要可以删除)
B 列包含这些转换后成绩的平均值
平均数是第一行中值 'Assignment' 的单元格数量的转换成绩之和。 (在这个样本中,有 10 个)
注意:
我确实在 Standard teached 的其他列中添加了一些值,因为转换计算需要它。
这是带有分步说明的代码:
function calculateGrade() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Gets data from the sheet named 'IN PROGRESS:Standard Taught'
var data = spreadsheet.getSheetByName('IN PROGRESS:Standard Taught');
var dataValues = data.getDataRange().getValues();
// Gets conversion data from the sheet named 'Conversion Chart'
var conversion = spreadsheet.getSheetByName('Conversion Chart');
var conversionValues = conversion.getRange('B3:I13').getValues();
// Get second row as our standard taught values
var standardTaught = dataValues[1];
// Number of first row cells containing 'Assignment'
var numAssignments = dataValues[0].filter(function(item){
if(item.match(/Assignment/)){
return item;
}
}).length;
var totalScore = 0;
// Process scores to grade
dataValues.forEach(function(row, rowIndex){
// Skip first two rows and succeeding rows that their first columns are blank
if(rowIndex > 1 && row[0]){
row.forEach(function(score, colIndex){
// Skip first two columns since they are not scores
if(colIndex > 1){
// Find what conversion table should be the scores are based (4, 3 or 2)
conversionValues[0].forEach(function(item, index){
// If standard taught for the column matches the first row of original grade column, that's the conversion table we are using
if(item == standardTaught[colIndex]){
// Find in the conversion table we are using the grade value of the score
for(var i = 0; i < conversionValues.length; i++){
for(var j = index; j < index + 1; j++){
if(conversionValues[i][j] === score){
var convertedGrade = conversionValues[i][j + 1];
// Set directly below cell of the score to the converted grade value
// You can remove the row below if you don't want to see the converted grade below the score
data.getRange(rowIndex + 2, colIndex + 1).setValue(convertedGrade);
// Skip cells that are not valid numbers/scores
if(!isNaN(parseFloat(convertedGrade))){
// Add all converted grades for the average
totalScore += parseFloat(convertedGrade);
}
}
}
}
}
});
}
});
// Set row's average score based on the total of converted grades over number of assignments
data.getRange(rowIndex + 1, 2).setValue(totalScore / numAssignments);
// Reset counter for total score for the next rows
totalScore = 0;
}
});
}
不需要脚本。
删除 B 列中的所有内容并在 B3 中使用:
=ARRAYFORMULA(IF(A3:A="",, QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A3:A="", 0,
IF(C2:AA2=2, IFNA(VLOOKUP(C3:AA, 'Conversion Chart'!H3:I, 2, 0)),
IF(C2:AA2=3, IFNA(VLOOKUP(C3:AA, 'Conversion Chart'!E3:F, 2, 0)),
IFNA(VLOOKUP(C3:AA, 'Conversion Chart'!B3:C, 2, 0)))))),
"select "&TEXTJOIN(",", 1,
"avg(Col"&ROW(A3:A)-ROW(A3)+1&")")&"")),
"select Col2")))
出于愚蠢的原因,我们需要将我们的 1-4 评分系统转换为 1-100 等级。
我的主要问题是,是否有比我正在做的 better/quicker/more 更有效的方法?下面的 B3 点差sheet 展示了我的方法。
我的目标是,教师可以输入他们教了多少标准以及学生达到了什么标准,sheet 会自动查看正确的换算表来拉分。
因此,如果老师教标准达到 4,而孩子得到 4,那就是 100。如果老师教 2,孩子得到 2,那仍然是 100。而如果老师教 4,而孩子得了 2,只有 78。
在B3你可以看到我要去的方向。一长串带有 vlookup 的 ifs。正如你所看到的,我需要为每项任务的每一种可能性做这件事。它似乎 就像可以告诉计算机做的事情,因为它一遍又一遍地重复,只有微小的变化。
谢谢!
我已经在 Google Apps 脚本中完成了答案,因为它更容易直接实施。
这是示例数据。
这是示例输出。
我直接将转换后的成绩放在每项作业的分数下方。 (如果需要可以删除)
B 列包含这些转换后成绩的平均值
平均数是第一行中值 'Assignment' 的单元格数量的转换成绩之和。 (在这个样本中,有 10 个)
注意:
我确实在 Standard teached 的其他列中添加了一些值,因为转换计算需要它。
这是带有分步说明的代码:
function calculateGrade() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Gets data from the sheet named 'IN PROGRESS:Standard Taught'
var data = spreadsheet.getSheetByName('IN PROGRESS:Standard Taught');
var dataValues = data.getDataRange().getValues();
// Gets conversion data from the sheet named 'Conversion Chart'
var conversion = spreadsheet.getSheetByName('Conversion Chart');
var conversionValues = conversion.getRange('B3:I13').getValues();
// Get second row as our standard taught values
var standardTaught = dataValues[1];
// Number of first row cells containing 'Assignment'
var numAssignments = dataValues[0].filter(function(item){
if(item.match(/Assignment/)){
return item;
}
}).length;
var totalScore = 0;
// Process scores to grade
dataValues.forEach(function(row, rowIndex){
// Skip first two rows and succeeding rows that their first columns are blank
if(rowIndex > 1 && row[0]){
row.forEach(function(score, colIndex){
// Skip first two columns since they are not scores
if(colIndex > 1){
// Find what conversion table should be the scores are based (4, 3 or 2)
conversionValues[0].forEach(function(item, index){
// If standard taught for the column matches the first row of original grade column, that's the conversion table we are using
if(item == standardTaught[colIndex]){
// Find in the conversion table we are using the grade value of the score
for(var i = 0; i < conversionValues.length; i++){
for(var j = index; j < index + 1; j++){
if(conversionValues[i][j] === score){
var convertedGrade = conversionValues[i][j + 1];
// Set directly below cell of the score to the converted grade value
// You can remove the row below if you don't want to see the converted grade below the score
data.getRange(rowIndex + 2, colIndex + 1).setValue(convertedGrade);
// Skip cells that are not valid numbers/scores
if(!isNaN(parseFloat(convertedGrade))){
// Add all converted grades for the average
totalScore += parseFloat(convertedGrade);
}
}
}
}
}
});
}
});
// Set row's average score based on the total of converted grades over number of assignments
data.getRange(rowIndex + 1, 2).setValue(totalScore / numAssignments);
// Reset counter for total score for the next rows
totalScore = 0;
}
});
}
不需要脚本。
删除 B 列中的所有内容并在 B3 中使用:
=ARRAYFORMULA(IF(A3:A="",, QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A3:A="", 0,
IF(C2:AA2=2, IFNA(VLOOKUP(C3:AA, 'Conversion Chart'!H3:I, 2, 0)),
IF(C2:AA2=3, IFNA(VLOOKUP(C3:AA, 'Conversion Chart'!E3:F, 2, 0)),
IFNA(VLOOKUP(C3:AA, 'Conversion Chart'!B3:C, 2, 0)))))),
"select "&TEXTJOIN(",", 1,
"avg(Col"&ROW(A3:A)-ROW(A3)+1&")")&"")),
"select Col2")))