Getting an average from an unconventional date and time string - google-sheets

I have an Alexa Routine where the date/time when I say goodnight is tracked in a Google Sheet - so I can see when I actually went to bed. Yup, everything can be tracked and measured these days!
But the entries are super weird and unhelpful strings, not dates and times:
Sample data:
January 23, 2021 at 11:29PM
January 25, 2021 at 12:03AM
January 25, 2021 at 11:27PM
January 26, 2021 at 11:17PM
Alexa just dumps these unconventional date/time strings into A1-A??? on the first tab.
My goal - to show my average bedtime each month. Usually I can hack my way to an answer but I'm having trouble converting these into the month/year and times, let alone finding a way to average them.
Turning to those who have madder skills than me!
Appreciated as always.

You can try this (in C1 given that your data starts from A2:A):
UPDATED:
= QUERY(ARRAYFORMULA(
IF(LEN(A2:A), {
MONTH(REGEXEXTRACT(A2:A, "\D+") & 1),
REGEXEXTRACT(A2:A, "\D+"),
IF(TIMEVALUE(REGEXEXTRACT(A2:A, "\d+:\d+.*")) > 0.5,
TIMEVALUE(REGEXEXTRACT(A2:A, "\d+:\d+.*")),
TIMEVALUE(REGEXEXTRACT(A2:A, "\d+:\d+.*")) + 1)
}, "")),
"Select Col1,Col2 ,avg(Col3) where Col1 is not null
group by Col1, Col2 Order By Col1 asc label Col1 '#', Col2 'Month', avg(Col3)
'Average bedtime'
")
Spreadsheet demo: HERE

You said your raw data strings run A1:A. That being the case, you could place the following in cell B1 (where Col B and Col C are both otherwise empty):
=FILTER(SPLIT(A:A," at ",0,1),A:A<>"")
This will create a real date in Col B and a real time in Col C for each string in Col A. From there, you can easily perform other functions. For instance, assuming you've got the above formula in B1, you could place the following in, say, E1:
=ArrayFormula(QUERY(FILTER({DATE(YEAR(B:B),MONTH(B:B),1),IF(C:C<0.5,C:C+1,C:C)*1},A:A<>""),"Select Col1, AVG(Col2) GROUP BY Col1 LABEL AVG(Col2) ''"))
... then format Col E (Format > Number > More Formats > Custom number format > mmm yyyy) and Col F (Format > Number > More Formats > Custom number format > h:mm am/pm).

Related

Comparing Dates in Google Sheets with different format

I tried everything and can't make this work.
File 1 has a date and transactions.
File 2 has date and other exported date from a software, so Column A is a date that is not formatted.
Basically I want to get the number of transactions per day on file 1, when in file 2 we have Column B with "google / cpc" and Column C contains "search".
The problem here is that I can't make the dates from File 1 to File 2 to compare to give me the transactions. It never compares.
File 1 https://docs.google.com/spreadsheets/d/1Xvoo2Rob3kI4duPpmCTfhMLPlvdzIJY9ZQBV7CHccoc/edit?usp=sharing
File 2 https://docs.google.com/spreadsheets/d/10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco/edit?usp=sharing
I tried to make the date from file 2 like the date from file 1 using concatenate and LEFT and RIGHT formulas, but they look similar to the eye, but google sheets can't compare.
I tried to also change the format to date and play with it, but still can't get them to compare the dates.
you can try this out:
=MAKEARRAY(31,1,LAMBDA(r,c,INDEX(LAMBDA(z,SUM(IFNA(FILTER(INDEX(z,,6),INDEX(DATE(LEFT(INDEX(z,,1),4),MID(INDEX(z,,1),5,2),RIGHT(INDEX(z,,1),2)))=INDEX(A3:A33,r),INDEX(z,,2)="google / cpc",REGEXMATCH(INDEX(z,,3),"(?i)search")))))(importrange("10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco","Sheet2!A:F")))))
they look similar to the eye, but google sheets can't compare
The values like 20230102 in spreadsheet 2 column A look like dates but are actually numbers in the neighborhood of 20 million, such as 20,230,102.
It is unclear whether your intention is to use that data in just this one report or several such reports. If the latter, you may want to Insert > Sheet in spreadsheet 1 and put this formula in cell A1 of that new 'Import' sheet to import and convert the data:
=arrayformula(
lambda(
ssId, datelikeRangeA1, criteriaRangeA1, transactionsRangeA1,
lambda(
dates, criteria, transactions,
query(
{ dates, criteria, transactions },
"select Col1, sum(Col3) where Col2 = 'google / cpc' group by Col1
label Col1 'Date', sum(Col3) 'Total transactions' ",
0
)
)(
to_date( value( regexreplace(
to_text( importrange(ssId, datelikeRangeA1) ),
"(\d{4})(\d{2})(\d{2})", "$1-$2-$3"
) ) ),
importrange(ssId, criteriaRangeA1),
importrange(ssId, transactionsRangeA1)
)
)(
"10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco",
"Sheet2!A2:A",
"Sheet2!B2:B",
"Sheet2!F2:F"
)
)
The formula may look a bit complex, but it is easy to adjust to other similar imports you may need by modifying the parameters at the end. You can then more easily to refer to the data in your various reports. To match the dates in Sheet1!A3:A33, put this formula in cell Sheet1!B3:
=arrayformula(
ifna(
vlookup(
A3:A33,
Import!A2:B,
columns(Import!A2:B),
false
)
)
)
Using your current formula,try changing your values with text and back to number with value:
=INDEX(IFNA(VLOOKUP(VALUE(TEXT(A3:A33,"yyyymmdd")), QUERY(IMPORTRANGE("10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco", "Sheet2!A:N"),
"select Col1,sum(Col6) where Col2 = 'google / cpc' and Col3 = 'search' group by Col1"), 2, 0)))

Conditional Formatting Dates whereby specific date range auto-suggests action

I am in the process of creating a documentation tracker however struggling to do the following:
add conditional formatting so that the background changes colour (green, yellow, red) based on how many days since documentation has last been reviewed/updated. So that the background colours change depending on the number of days or months whichever is easier.
Based on the date, in the Action column for any dates greater than 3 months/90 days want it to automatically indicate check likewise for dates within a month or less no need to check
Link to documentation tracker google sheet: https://docs.google.com/spreadsheets/d/1DTyEg7JQcrTqCFQqgxrJEadOG8PcnI5khOrpOssZvyo/edit?usp=sharing
Example of a document which i got the status idea: https://docs.google.com/spreadsheets/d/1s8CXs-Q4qs7KeykxAlBF2cGfw7th-DGIqle6yLAVOxE/edit?usp=sharing
Thanks in advance! Will be extremely grateful for any help, guidance and advice!
Based on what you've provided so far, here is the basic conditional formatting to get you started.
https://docs.google.com/spreadsheets/d/1_AvM9sPlxUSlToqWf7t6oSKak5K7ALc_S4XjgO5o4q0/edit?usp=sharing
The custom formula for the conditional formatting looks like this:
=AND(TODAY()-E2 > 90, E2 <> "")
So if the date in E2 is older than 90 days, mark that cell in RED. This rule applies to the whole column, E2:E.
Similarly, a checkmark is added in the Action column for dates older than 90 days, by the formula in F1. Do you also mean that dates less than 30 days old should be always unchecked, but dates between 90 and 30 days, should be left as they are, either checked or not?
Let us know if this is what you are hoping for.
Update: The Action column is calculated based on the difference between today's date and your date value in Column E. It is really duplicating the RED highlighting, so doesn't really help you. If it is a field that you want to be able to update, you'll probably need to change the Arrayformula to a dragdown formula, which you cana then overtype if putting a checkmark in a cell.
Okay, it is not a very elegant solution, and I know some experts would have a much better solution, but I think it does what you want.
See my tab "Iteration 2-GK" in your new sheet.
You can change the dates in column I to see if the Summaries colours change the way you expect. I haven't done Technical or Stakeholders yet, but they would be the same.
I came up with a complex formula to apply the same logic used in the conditional formatting rules for Column I, to apply conditional formatting for column C. Note that I added a hidden column B, to add the ProductName onto each row. I also removed the merged cells in columns A-E.
The formula to check whether the dates in column I fall in a certain range, and then to count which range occurs most frequently (ie. also the most frequent colour in column I for each product) is:
=iferror(choose(
match(
max(
{iferror(query({B$3:B,I$3:I},
"select count(Col2) where Col1 = '"& B3 & "' and Col2 < date '"&TEXT(today()-180,"yyyy-mm-dd")&"' label count(Col2) '' ",0),""),
iferror(query({B$3:B,I$3:I},
"select count(Col2) where Col1 = '"& B3 & "' and Col2 < date '"&TEXT(today()-31,"yyyy-mm-dd")&"' and Col2 >= date '"&TEXT(today()-180,"yyyy-mm-dd")&"' label count(Col2) ''",0), ""),
iferror(query({B$3:B,I$3:I},
"select count(Col2) where Col1 = '"& B3 & "' and Col2 < date '"&TEXT(today() ,"yyyy-mm-dd")&"' and Col2 >= date '"&TEXT(today()-31, "yyyy-mm-dd")&"' label count(Col2) ''",0), "")}),
{iferror(query({B$3:B,I$3:I},
"select count(Col2) where Col1 = '"& B3 & "' and Col2 < date '"&TEXT(today()-180,"yyyy-mm-dd")&"' label count(Col2) '' ",0),""),
iferror(query({B$3:B,I$3:I},
"select count(Col2) where Col1 = '"& B3 & "' and Col2 < date '"&TEXT(today()-31,"yyyy-mm-dd")&"' and Col2 >= date '"&TEXT(today()-180,"yyyy-mm-dd")&"' label count(Col2) ''",0), ""),
iferror(query({B$3:B,I$3:I},
"select count(Col2) where Col1 = '"& B3 & "' and Col2 < date '"&TEXT(today() ,"yyyy-mm-dd")&"' and Col2 >= date '"&TEXT(today()-31, "yyyy-mm-dd")&"' label count(Col2) ''",0), "")},
0),"red","yellow","green"),"")
I haven't got this to work, so it needs to be dragged down column C from cell C3.
Will you need to add rows for a product, if you come up with more documentation? I haven't tested yet if this will work when adding rows.

How could I form a string of items grouped by a matching value? (e.g. "Red: Apples, Cherries")

I'm wondering if there is a decent way to do this (without scripts) - if not, I can attempt creating a script for it but some users of this sheet will be using Excel on their computers so I'm trying to keep it scriptless as much as possible.
I have a sheet set up to display text based on certain conditions that is meant to be copied and pasted into an external program.
There is a column for months jan-dec and a column next to that where the user can input a number from 1-10 (and those numbers are associated with strings that are found with Vlookup on another sheet. They're basically "error codes" just to keep the sheet clean. But I'm just omitting this part because it's not needed for this question)
Right now, the text that populates shows:
Jan: 1
Feb: 2
Apr: 1
How could I group these by the value instead of listing them separately? Something like:
1: Jan, Apr
2: Feb
Is it possible to grab the items from that months list and put them in their own lists?
This is the current formula for reference:
=if(countif(Calculator!B2:B13,">0"),CONCATENATE(C2:C13),"None")
(Calculator sheet)B2:B13 --> column with the numbers
(Data sheet)C2:C13 --> a concatenated string that contains the month name from one cell and the number (or technically the string associated with that number as I mentioned before)
Each cell in the C column has the Jan: 1, Feb: 2 data and any month without data is left blank. When I concatenate the C cells together, it automatically omits the blank cells which is helpful but now I'd really like to group them by that value instead.
Here is the example sheet that reflects this
delete A15 and paste this in A14:
={""; ARRAYFORMULA(TEXTJOIN(CHAR(10), 1, REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(QUERY({A2:A13&",", B2:B13&":"},
"select max(Col1)
where not Col2 matches ':'
group by Col1
pivot Col2"),,9^9))), ",$", )))}
UPDATE:
if order matters...
={""; ARRAYFORMULA(TEXTJOIN(CHAR(10), 1, REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(QUERY({"♦"&ROW(A2:A13)&"♦"&A2:A13&",", B2:B13&":"},
"select max(Col1)
where not Col2 matches ':'
group by Col1
pivot Col2"),,9^9))), "♦\d+♦|,$", )))}
UPDATE:
={""; ARRAYFORMULA(JOIN(CHAR(10), SUBSTITUTE(REGEXREPLACE(TRIM(QUERY(QUERY({
SORT(FILTER({SUBSTITUTE(A1:A12, "'", "/"&20)*1, B1:B12&":"}, B1:B12<>""), 2, 1, 1, 1)},
"select max(Col1)
group by Col1
pivot Col2
format max(Col1) 'Mmm♦yy,'"),,99^99)), ",$", ), "♦", CHAR(39))))}

Grouped average within ARRAYFORMULA only for past dates

I need to average the values that share the same ID and have been published in the same or previous months. I have to use ARRAYFORMULA due to the volume of rows.
This is an iteration of a question I asked last week: How to use AVERAGEIFS within ARRAYFORMULA, which I've tried to adapt for this, unsuccessfully.
As it can be a little confusing, I have created this file with dummy data. Although year and month were included in the ID at the beginning, I have split them into columns to make filtering easier.
Note that February average includes January values with the same ID, March includes January, February and March, etc. When the year changes, the average restarts. I suppose it could be done by comparing the values of the year (equals) and month (equals or lower), but I don't know how to insert the comparator into the last-day formula.
Thank you all for your time and effort.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B&C2:C; QUERY({A2:A&B2:B&C2:C\D2:D};
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
label avg(Col2)''"; 0); 2; 0)))
or if months does not matter use:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B; QUERY({A2:A&B2:B\D2:D};
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
label avg(Col2)''"; 0); 2; 0)))

Locate two values "empty" and "incomplete", add the values that is one column before

I am creating a spreadsheet for homework completion. I want to search "empty space" and "incomplete" and add everything into one cell. everything is in one row.
I didn't do anything. I don't know how to start. I) would prefer a formula rather than a javascript.
For example:
John Doe has homework "empty" and "incomplete". I want to find these entries, go back one column where the actual homework is and concatenate it at the end of the row for example "p 34, p 35, p 37".
as a bonus, I would like maybe to add a due date for these homeworks. The date is located two rows up and 4 columns to the left from "empty" and "incomplete" cells.
For example: "p 34 due date was: July 27, 2019, p 35 due date was: July 24, 2019, p 37 due date was: July 21, 2019".
try like this
=TEXTJOIN(", ", 1, QUERY({C8:D8;H8:I8;M8:N8;R8:S8;W8:X8;AB8:AC8},
"select Col1
where Col1 is not null
and (Col2 = 'Incomplete'
or Col2 = '')", 0))

Resources