How can I write a function in google sheets that gives me the group of 15 consecutive cells with the highest average? [duplicate] - google-sheets

This question already has answers here:
Google Sheets: Moving daily, weekly, monthly, and yearly averages
(2 answers)
Closed 24 days ago.
I've got a data set of 365 cells about the wave height per day, I want to figure out how to find when the highest average over 15 days is during the year. I am limited to using google sheets and have beginer to intermediate knowledge of google sheets which makes it hard to figure out how to write the function.
I have no clue how to get there, all i could figure out online is using the function to find the highest 10 values in a dataset, but not consecutive values.

With the use of SCAN, SEQUENCE and INDEX, you can navigate through the range, choosing ranges of 15 cells; and returning the average:
=SCAN("",SEQUENCE(COUNTA(A1:A)-14),LAMBDA(a,v,AVERAGE(INDEX(A:A,v):INDEX(A:A,v+14))))
Just by wrapping that into MAX would give you only the value. If you need also the range, can do something like this:
=SCAN("",SEQUENCE(COUNTA(A1:A)-14),LAMBDA(a,v,{"Rows: "&v&" to "&v+14,AVERAGE(INDEX(A:A,v):INDEX(A:A,v+14))}))
That would return:
With the help of SORTN you'll be able to find the highest value (or values, just change the first 1 after the closure of SCAN with the value you want):
=SORTN(SCAN("",SEQUENCE(COUNTA(A1:A)-14),LAMBDA(a,v,{"Rows: "&v&" to "&v+14,AVERAGE(INDEX(A:A,v):INDEX(A:A,v+14))})),1,1,2,0)
To have the actual values, use:
=LAMBDA(ind,FILTER(A:A,ROW(A:A)>=C1,ROW(A:A)<(C1+15)))(INDEX(SORTN(SCAN("",SEQUENCE(COUNTA(A1:A)-14),LAMBDA(a,v,{v,AVERAGE(INDEX(A:A,v):INDEX(A:A,v+14))})),1,1,2,0),,1))

Related

Summing a Cell across all sheets formatted as Duration [duplicate]

This question already has answers here:
How to SUM duration in Google Sheets?
(5 answers)
Closed 8 months ago.
So i have a google sheets with multiple sheets for which i track my reading stats, each sheet is one book. I would like to have a totals sheet which displays some stats calculated for all my books(sheets).
For example i have cell with tracks the Duration a book has taken, its always the same cell in every sheet(I3) this cell uses the SUM() function to sum all the durations for each day.
Its formatted in the "Duration" mode in sheets it takes 01:20:59.000 and displays it as 1:20:59.
I would like a function which sums the duration for all for example I3 Cells in all my sheets.
I have tried various scripts i found to make this work, but non of them worked with the Duration Format just with plain numbers.
try:
=ARRAYFORMULA(TEXT(SUM(IFERROR(TIMEVALUE({Sheet1!I3; Sheet2!I3}))); "[h]:mm:ss"))

Google sheets- how to calculate the average value of the last n days, given that n number is variable?

I need some help to calculate the moving average of the previous n days to date, given that n number is variable due to any given day can contain multiple values insertion (usually from 2 to five). So one specific day can contain several values.
This sheet is specifically related to weight tracking, here is the link:
https://docs.google.com/spreadsheets/d/1KhewGXtpElPYtjM4RpA4j2b9fkz17XcA518SPImg4p8/edit?usp=sharing
in the image you can see that for yyyy-mm-dd 2021/07/13 i want the average of the previous 54 and 55 values respectively
Thanks
I see no reason why this wouldn't be possible with a regular AVERAGEIFS() function. Did that not come up during your googling this question?
Here is a sheet created specifically for this question.
And here is the AVERAGEIFS() that I wrote in cell C3 on the MK.Help tab.
=IF(A3<A$3+C$1;;AVERAGEIFS(B:B;A:A;"<="&A3;A:A;">="&A3-C$1))

Google Sheets AVERAGE function in ARRAYFORMULA

I want to use the ARRAYFORMULA version of =IFERROR(AVERAGE(B29:H29),""). This is to calculate a 7 column rolling average that will automatically drag across using the array formula. I am aware the AVERAGE cannot be used with ARRAYFORMULA but I have struggled to find an alternative.
As discussed in the comments you can modify the previous answer.
Another approach to get the running average of the current number and the next 6 numbers is to take the difference of two running sums and divide by the count like this:
=ArrayFormula(if(C1:1="","",
(sumif(column(C1:1),"<"&column(C1:1)+7,C1:1)-sumif(column(C1:1),"<"&column(C1:1),C1:1))/
countifs(column(C1:1),"<"&column(C1:1)+7,column(C1:1),">="&column(C1:1),C1:1,"<>")))
(you can't use AVERAGEIFS or SUMIFS because they don't work with array formulas).
For completeness, the more usual running average starting with the first number, then the average of the first two numbers etc. would be given by:
=ArrayFormula(if(C1:1="","",
(sumif(column(C1:1),"<="&column(C1:1),C1:1)-sumif(column(C1:1),"<="&column(C1:1)-7,C1:1))/
countifs(column(C1:1),"<="&column(C1:1),column(C1:1),">"&column(C1:1)-7,C1:1,"<>")))

Google spreadsheet convert values from thousands to millions [duplicate]

This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 1 year ago.
I have a spreadsheet full of data that each number represent thousand
For example: 1,745 represent 1,745,000
How can I convert each number (in the same cell) to represent millions so 1.745 will represent 1,745,000?
In MS Excel it can be done with special paste divide by 1000.
What's the equivalent in Google spreadsheet ?
Thanks!
Sheets' concept of thousands and millions is the same as Excel's (not everything else is however). Sheets does not, at the moment, have a direct equivalent of Excel's Paste Special with Operation.
If you want to convert each number representing thousands (in the same cell) to represent millions in Sheets then you will have to have each be divided by 1000. If you want this without helper cells you probably will need to write a script, though you could edit each cell individually or might export to Excel, use their inbuilt code and import back into Sheets, if required there.
if the number is 1,745 you can't change it in the same cell to million equivalent
if the number is 1.745 you can change it in the same cell but only "visually" to million equivalent with custom number formatting:
note1: its only visual change if you keep one eye shut
note2: this applies to the sheet with US locale. if you want to reverse it use some European locale

Getting Average m:s:ms time in Google Sheets

I am working on a Google Sheets file in order to get Track and Field Data.
The times run by the athletes are:
1:58.66
2:00.03
2:00.31
2:01.85
2:03.07
2:03.18
2:03.57
... etc.
In total I have 141 values. I have tried looking for functions to help me with this, but it seems as though these values are not accepted as numbers.
I need the average of all 141 times.
There is no direct way to get this done in excel, but you can achieve it using the following function (assuming your data is stored in column A)
=ARRAYFORMULA(sum(60*left(A1:A)+right(A1:A,5)))/COUNTA(A:A)
So, I used arrayfunction to go through the whole list at column A and converted it into seconds, then divided it by its count (using COUNTA for non-numeric values) to get the average seconds for all athletes.
You can export date in mm:ss.00 format again using this function,
=TEXT(B1/(24*60*60),"mm:ss.00")
Please note that TEXT function receives value (in days), hence you will have to divide the first function result (assumed it is at B1) by 24*60*60.
enjoy...

Resources