Google sheets 如何对该数据子集的columnA值和MAX(columnB)进行过滤?
我有以下数据问题,我正试图找出如何封装在Google Sheets公式或查询中:Google sheets 如何对该数据子集的columnA值和MAX(columnB)进行过滤?,google-sheets,google-sheets-formula,google-sheets-query,Google Sheets,Google Sheets Formula,Google Sheets Query,我有以下数据问题,我正试图找出如何封装在Google Sheets公式或查询中: Player Game Shots Scored Washington 1 3 Lincoln 1 6 Roosevelt 1 4 Washington 2 3 Grant 2 1 Kennedy 2 3 我感兴趣的是计算平均投篮得分占比赛得分最高的球员的百分比。或者,换句
Player Game Shots Scored
Washington 1 3
Lincoln 1 6
Roosevelt 1 4
Washington 2 3
Grant 2 1
Kennedy 2 3
我感兴趣的是计算平均投篮得分占比赛得分最高的球员的百分比。或者,换句话说:
For a Player P:
Return the Average of(
For Each Distinct Game containing P (
P.Points / Max(Points)
)
)
例如,使用上述数据,我看到的结果是:
Player Performance
Washington 75% [=(3/6+3/3)/2 * 100%]
Lincoln 100%
Roosevelt 66%
Grant 33%
Kennedy 100%
然而,事实证明,这种复合计算很难翻译成谷歌查询语言——有什么帮助吗
=唯一过滤器A2:C,A2:A=华盛顿
返回华盛顿玩家的所有行,但可能会丢失该游戏中得分最高的人的数据。是否有办法将该行也包括在筛选器中?您可以通过在Google Apps中创建的脚本来完成此操作。要实现此目的,请执行以下步骤: 在电子表格中,选择工具>脚本编辑器以打开绑定到文件的脚本。 在脚本编辑器中复制此函数,并保存项目: 函数GETAVERAGESinput{ const games=Array.fromnew Setinput.maprow=>行[1]。mapgame=>{ 让maxResult=Math.max…input.filterrow=>row[1]===game.maprow=>row[2]; return[game,maxResult];//获得每场比赛的最大分数 }; 返回Array.fromnew Setinput.maprow=>行[0]。mapplayer=>{ 让playerRows=input.filterrow=>row[0]==player;//根据player筛选行 让百分比=playerRows.reduceAc,行=>{//当前播放器的百分比总和 让maxGame=games.findgame=>游戏[0]==行[1][1];//当前游戏的最大分数 返回acc+行[2]/maxGame;//累计百分比 }, 0; 让平均值=百分比/playerRows.length;//除以每个游戏数的累积值 return[player,average];//返回player name和相应average的数组 }; } 现在,如果你回到你的电子表格,你可以使用这个函数,就像你在使用一个常规的表格公式一样。在本例A2:C7中,您只需提供适当的范围作为参数,如下所示: 参考: