I have the following data in google sheets (or excel). I want to compare the dates in column B and C to determine if they occurred in the same year, without changing the format of the dates or adding the example column D below.
Then, if they did occur in the same year, I want to count how many for that specific year.
A B C D
1 7/7/2020 11/18/2021 (No)
2 8/25/2021 11/17/2021 (Yes)
3 5/27/2021 10/27/2021 (Yes)
4 12/8/2020 10/27/2021 (No)
5 3/27/2019 10/18/2021 (No)
6 1/25/2018 6/30/2018 (Yes)
What I am trying to show/count:
Year - Count
2021 - 2
2020 - 0
2019 - 0
2018 - 1
Thank you in advance for your help!
try:
=INDEX(IFNA(REGEXEXTRACT(TO_TEXT(B1:B), "\d{4}")=REGEXEXTRACT(TO_TEXT(C1:C), "\d{4}")))
and then:
=INDEX(QUERY(IFNA({
REGEXEXTRACT(TO_TEXT(B1:B), "\d{4}"), (
REGEXEXTRACT(TO_TEXT(B1:B), "\d{4}")=
REGEXEXTRACT(TO_TEXT(C1:C), "\d{4}"))*1}),
"select Col1,sum(Col2) where Col1 is not null
group by Col1 label sum(Col2)''"))
Try
=query(ARRAYFORMULA({year(A1:A6),if(year(A1:A6)=year(B1:B6),1,0)}),"select Col1,sum(Col2) group by Col1")
If dates are in text format, use
=query(ARRAYFORMULA(
{REGEXEXTRACT(TO_TEXT(A1:A6),"[0-9]{4}"),if(REGEXEXTRACT(TO_TEXT(A1:A6),"[0-9]{4}")=REGEXEXTRACT(TO_TEXT(B1:B6),"[0-9]{4}"),1,0)}),
"select Col1,sum(Col2) group by Col1")
Related
I need a formula that will count the dates in column A and show how many of each month.
Example of the data in Column A
12/1/21
12/10/21
12/29/21
12/30/21
1/11/22
1/12/22
5/2/22
The returned data would be (or similar - I just need to know the total per month over the years)
12/21 - 4
1/22 - 2
5/22 - 2
and so on.
Here is what I go so far.
=ArrayFormula(month('tab name'!A2:A10))
but this list the months and not counts them.
use:
=INDEX(QUERY(TEXT(A1:A, "mmm e"),
"select Col1,count(Col1)
where Col1 <> 'Dec 1899'
group by Col1
label count(Col1)''"))
A B C
1 Timestamp Hours Worked Total Hours
2 1/2/2022 17:33:41 6
3 1/3/2022 19:59:41 2 January =
4 1/7/2022 13:20:51 1
5 1/9/2022 12:49:02 3 February =
6 1/15/2022 12:04:21 3
7 2/16/2022 15:58:10 9 March =
8 2/22/2022 11:57:31 3
9 2/24/2022 5:45:12 5
10 2/2/2022 17:33:41 4
11 2/3/2022 19:59:41 2
12 2/7/2022 13:20:51 1
13 3/9/2022 12:49:02 3
14 3/15/2022 12:04:28 3
15 3/16/2022 15:58:10 7
16 3/22/2022 11:57:31 3
17 3/24/2022 5:45:12 5
I would like to sum the hours by date/month. I can sum the hours by
column, =sum(b2:b). But how do I sum the hours in Column B by
date/month of column A?
In another post, a member referenced the 'Google Sheets function list'.
I have found that to be very helpful on other things I have been doing.
But I am still at a lose for this problem.
John
You could use the query function with SQL:
=QUERY({(data)}, "select sum(Col2) group by Col1 label Col1 'Date', Col2 'Sum'")
That would return a new table, and you can adjust it by changing the second parameter, representing the SQL string. You can view Google's docs for the query function here. In addition you can find their docs for the query language here.
The simplest solution, without any formula, is to build a pivot table.
use:
=ARRAYFORMULA(REGEXREPLACE(TO_TEXT(QUERY({TEXT(A2:A, "yyymm\×mmmm"), B2:B},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label sum(Col2)''")), "(.*×)", ))
I have something like this:
date value
2022/01/02 4
2022/01/02 3
2022/01/01 2
2022/01/01 1
and I want another table computed from that which has a single row for each date and the sum of the values for that date:
Date Value
2022/01/02 7
2022/01/01 3
etc...how?
solution #1
Use a pivot table to do what you expect !
solution #2
=SORT(QUERY(A2:B,"select A,sum(B) group by A label sum(B) ''"))
with duration, use
=SORT(QUERY({A2:A,arrayformula(value(B2:B))},"select Col1,sum(Col2) group by Col1 label sum(Col2) ''"))
I have the following table:
What I'm trying to do is to write a formula that totals by each unique day in the month and year given in B1 and C1 thus the output should be:
I'm not sure how to start with this, googling seems to suggest the use of SUMIF.
Sheet is here
try:
=QUERY(FILTER({A5:B, TIMEVALUE(C5:C)}, MONTH(A5:A)=MONTH(B1&1), YEAR(A5:A)=D1),
"select Col1,sum(Col3)
where Col1 is not null
group by Col1
label sum(Col3)''
format sum(Col3)'[hh]:mm'", 0)
I have a Query formula in Google Sheets where I'm trying to set a condition that shows rows where Col1 > (Col2 +15 days). I'm not sure how to do the math on the +15 days in the Query formula.
I tried the following code:
=Query(A:B,"Select * where Col1>Col2+15")
I want it to show me where Column 1 is greater than the Col2 date + 15 days
Or you can use Datediff within your query:
=Query(A:B,"Select * where A is not null and datediff(A,B)>15")
See
I would add into the query {A:B,B:B+15}. This will add a third column into your selection with Col2+15 days. Then from there, you can select the first two columns, but still ask whether Col1 is greater than Col3.
=arrayformula(query({A:B,B:B+15},"select Col1,Col2 where Col1 > Col3"))
=ARRAYFORMULA(TO_DATE(QUERY(VALUE(A1:B),
"select * where Col1 > Col2+15", 0)))