当年话下
你可以定义一个函数function countTiersByMonth ( dataTable, firstline, lastline ) { var result = [ [0,0,0],[0,0,0],[0,0,0], [0,0,0],[0,0,0],[0,0,0], [0,0,0],[0,0,0],[0,0,0], [0,0,0],[0,0,0],[0,0,0] ]; var dates; var tiers; var month; for(i = firstline; i<=lastline; i++) { dates = dataTable.getRange(i,22).getValue(); tiers = dataTable.getRange(i,14).getValue(); month = new Date(dates).getMonth(); switch (tiers){ // we filter by tiers because it seems that you only care about // tiers 1, 2, 3 wheras you care about all the months case 1: case 2: case 3: result[month][tiers-1]++; //+1 for the respective tier // of the respective month break; //other tiers are ignored }; }; return result;};这需要数据表,第一个重要行(在您的示例中为 8)和最后一个相关行(在您的示例中为“j”)并输出一个包含 12 个元素的数组,每个月一个,每个包含 3 个元素,一个用于您想要计算的每一层。如果你愿意,让我们说五月的结果,你打电话tierlist = countTiersByMonth(oppwon, 8, j) // We do the counting hereprint(tierlist[4][0]) // arrays start at 0, so May -> [4], Tier 1 -> [0]print(tierlist[4][1]) // May, Tier 2print(tierlist[4][2]) // May, Tier 3