r/GoogleAppsScript • u/sherifzorkani • May 26 '21
Question Average excluding Highest and Lowest values
Hello,
need to create a custom function (to be used in Google sheets) that calculates average excluding highest and lowest values included in any range
for example Range ( 1 2 3 4 5 6 ) function to exclude 1 and 6 and calculates average of ( 2 3 4 5 )
so I think it can conclude sum(range) - max(range) - min(range) /count(range) -2
Thanks in Advance :)
6
Upvotes
1
u/paulcole710 May 27 '21 edited May 27 '21
What if the values are (1,1,1,2,3,4,5,6,6,6)?
Remove every 1 and every 6 or just one of each?
What about (1,2) or (1,1,1,1,1)?
Does the former return anything? Does the latter return 1 or nothing at all?
0
3
u/TobofCob May 26 '21
Here you go! Sorry if any formatting issues. I commented the code to be more readable. This will check that all values are integers, then will remove min and max values, then will return the average.