Google Sheets: How to count array entries in current weeknum? - google-sheets

I have a spreadsheet that has data in one column (H2:H500) and dates in another column (F2:F500). I would like a sum of the total number in the past work week (Monday-Friday). I'm not sure if I need to use =CountIfs or what. Any help would be greatly appreciated!
=COUNTIFS(F2:F500,WEEKNUM(TODAY(),1),H2:H500, "<>")
...doesn't seem to work. Am I close?

=COUNTA(QUERY({A2:B},
"select Col1
where Col2 is not null
and Col1 >= date '"&TEXT(DATE(YEAR(TODAY()),1,1)-WEEKDAY(DATE(YEAR(TODAY()),1,1),3)+7*
(WEEKDAY(DATE(YEAR(TODAY()),1,1),3)>3)+7*(WEEKNUM(TODAY())-2),"yyyy-mm-dd")&"'
and Col1 <= date '"&TEXT(DATE(YEAR(TODAY()),1,1)-WEEKDAY(DATE(YEAR(TODAY()),1,1),3)+7*
(WEEKDAY(DATE(YEAR(TODAY()),1,1),3)>3)+7*(WEEKNUM(TODAY())-2)+4,"yyyy-mm-dd")&"'"))

Related

Google sheet query has no output

Very strange, a query function I have used for years with no issue is not working on my latest google sheet.
It keeps saying no output even though I know it should have an output.
This is the query
=(Query(Results!A2:E,"Select A,C,B,D,E Where A >= date '"&TEXT(B10,"yyyy-MM-dd")&"' and A <= date '"&TEXT(B10,"yyyy-MM-dd")&"' "&if(len(J6)," and C='"&J6&"' ",)&" Order by A Desc",0))
You can view the sheet at:
https://docs.google.com/spreadsheets/d/1vobnovcVLpMM3lbbDXPekNAkoj_zhlG5Kd5ksQg5rVg/edit?usp=sharing
Your help is greatly appreciated
Transform Column A in dates by
=arrayformula(iferror(int(A2:A*1),date("20"&mid(A2:A,7,2),mid(A2:A,1,2),mid(A2:A,4,2))*1))
try:
=ARRAYFORMULA(QUERY({TO_DATE(1*REGEXREPLACE(TO_TEXT(Results!A2:A),
"(\d+)/(\d+)/(\d+)(?:.*)?", "$2/$1/$3")), Results!A2:F},
"select Col1,Col4,Col3,Col5,Col6
where Col1 >= date '"&TEXT(D4, "yyyy-MM-dd")&"'
and Col1 <= date '"&TEXT(G4, "yyyy-MM-dd")&"'"&IF(LEN(J6),"
and Col4='"&J6&"' ",)&"
order by Col1 desc", 0))

Google Sheets - Count Unique Values of Importrange Data between Given Dates

I have a sheet with a Name Column and corresponding Date column. I'm attempting to count the number of times unique Names appear for a specific Date range. The data is in a separate spreadsheet, so I'm using importrange in the formulas.
I created a sample spreadsheet here - we can pretend that the "Data" tab is on a separate spreadsheet file. I have the below formula so far but I'm not sure how to tell it to only count the unique Name values between the Dates in cells B2 and C2.
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1VHR-T9bo0E1KH4yZp-9wTW6JGjKh4b3qMdm99MP_vB8/edit#gid=0","Data!A:B"),"Select Count(Col1) where Col2 >= date '"&TEXT(B2,"yyyy-mm-dd")&"' and Col2 <= date '"&TEXT(C2,"yyyy-mm-dd")&"' Label Count(Col1) ''")
Thanks for your help!
This formula should do it:
=COUNTUNIQUE(QUERY(IMPORTRANGE("1VHR-T9bo0E1KH4yZp-9wTW6JGjKh4b3qMdm99MP_vB8","Data!A2:B"),"select Col1 where Col2 >= date '"&TEXT(B2,"yyyy-mm-dd")&"' and Col2<= date '"&TEXT(C2,"yyyy-mm-dd")&"'",0))

How to sum values for each day in google sheets

I want to make two columns one that has date and the other that has sum for the number of violations occurred on that day. Have a look at the data below.
use:
=QUERY({B:C}; "select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col1)''")

Total by day in google sheets for a given month and year

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)

Google Sheets Query where Date is Greater than Another Date + 15 Days

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)))

Resources