Google spreadsheet if weeknum yes/no not working - google-sheets

I am trying to use this formula in google spreadsheet (B2 is a date, eg. 27.11.2020):
=IF(WEEKNUM(now()) = WEEKNUM(B2),"yes","no")
For some reason this is not possible.
When using only:
=WEEKNUM(now()) = WEEKNUM(B2)
I do get TRUE/FALSE, but I need to be able to convert the TRUE/FALSE to YES/NO.
Why does not this work and are there any alternatives?

Issue:
As you can see in the following screenshot or in the documentation:
WEEKNUM accepts a date object but you are passing a string 27.11.2020.
Solution:
You need to convert 27.11.2020 to an actual date object.
You can do that by using this formula:
=IF(WEEKNUM(now()) = WEEKNUM(date(right(B2,4),mid(B2,4,2),left(B2,2))),"yes","no")

You can use the following
=IF(WEEKNUM(now())
=WEEKNUM(REGEXREPLACE(B1,"\.","/")),"yes","no")
OR
=IF(WEEKNUM(now())
=WEEKNUM(SUBSTITUTE(B1,".","/")),"yes","no")
The above formulas work for both European as well as USA formats.
Functions used:
REGEXREPLACE
SUBSTITUTE
IF

Related

SUMIFS and/or QUERY inside ARRAYFORMULA

Google spreadsheet sample: https://docs.google.com/spreadsheets/d/1MdRjm5QmKY_vaah9c3GrvH6dDOBCQX_zvCubvN0akmk/edit?usp=sharing
Im trying to get the sum of all values for each ID. The values im trying to add up are found in the Source tab while the calculations are done in the Output. My desired values are based on 2 things: ID and Date. The Id is supposed to match and the Date is supposed to be February. I tried first just using a sumif with just matching ID and it worked using this formula: =ARRAYFORMULA(IF(A2:A="",, SUMIF(Source!A:A,A2:A,Source!B:B)))
But when I add the 2nd critera and use a sumifs function, it only outputs for the first id. Here is the sumifs formula I used: =ARRAYFORMULA(SUMIFS(Source!B2:B,Source!A2:A,A2:A,Source!C2:C,">="&DATE(2021,2,1),Source!C2:C,"<="&DATE(2021,2,28)))
I tried using query as some of the answers I found online suggested to use it but it also outputs the first data only, here is the query formula I used =ARRAYFORMULA(QUERY(Source!A2:C,"select sum(B) where A = '"&Output!A2:A&"' and C >= date '"&TEXT(DATEVALUE("2/1/2021"),"yyyy-mm-dd")&"' and C <= date '"&TEXT(DATEVALUE("2/28/2021"),"yyyy-mm-dd")&"' label sum(B) '' "))
I know this is possible by making a temporary query/filter where you only include desired dates and from there I can use SUMIF, but I will be needing to make a monthly total and making 12 of these calculated temporary filters/query would take up a lot of space since we have a lot of data so I want to avoid this option if possible. Is there a better fix to this situation?
Solved by Astrotia - =arrayformula(sumif(I3:I20&month(K3:K20), A2:A6&2, J3:J20))

Google Sheet wrong date and time format for Timeline Graph

I import Tasker data source into a Google Sheet, but Timeline Graph does not work.
The format of the Date and Time is not understood.
The format of my data source is dd-MM-YYYY HH.mm
For example:
16-10-2020 00.40
But Google Sheet understands only dd/MM/YYYY HH:mm:ss
16/10/2020 00:35:00
See here
(On the second picture, I modified the date to be 16/10/2020 00:35:00, and applied Date and Time format, so it display 16-10-2020 00.35, which serves no purpose other than confusing you)
I've tried to change the format of the date, but the only thing it does is:
Convert an already existing 16/10/2020 00:35:00 format
To 16-10-2020 00.40
I want the opposite.
I'm tired and kind of angry at Google Devs. I'm been searching for hours, and I find it crazy Google Sheet cannot understand this simple format.
Please any idea?
Thank you
Please use the following formula to convert your values to dates
=ARRAYFORMULA(IF(A2:A5="",,--REGEXREPLACE(REGEXREPLACE(A2:A5,"-","/"),".",":")))
Depending on your locale you may have to change , to ;
=ARRAYFORMULA(IF(A2:A5="";;--REGEXREPLACE(REGEXREPLACE(A2:A5;"-";"/");"\.";":")))
Functions used:
ArrayFormula
REGEXREPLACE
An alternative to the solution already provided
Google Sheets Formulae
You can use this formula in order to replace the . with : and drag it down in order for it to be applied to all the cells:
=REPLACE(A1,14,1,":")
This will result in a column with the date formatted in the way you want it.
Google Apps Script
You can also make use of Apps Script in order to replace all the . with : directly in the sheet.
// Copyright 2020 Google LLC.
// SPDX-License-Identifier: Apache-2.0
function toDate() {
var ss = SpreadsheetApp.openById("SS_ID").getSheetByName("SHEET_NAME");
var range = ss.getRange(1,1,NO_OF_ROWS,1);
var values = range.getValues();
for (let i=1; i<values.length; i++)
ss.getRange(i, 1).setValue(new Date(values[i-1][0].toString().replace(/\./g, ":")));
}
The script above also sets the value to be of type date.
Reference
REPLACE formula Google Sheets;
Google Apps Script.

Google Sheets Query: Bring data by date in cell

I am trying to query a google sheet by date. I have done some research and learned I need to convert to TEXT format so that I can run the comparison, but I am not able to get the syntax correctly:
=query('SheetName'!$A2:$S, "select A Where O=date'"&TEXT(B2,"yyyy-mm-dd")&)
Could you give me some guidance?
Some more info: in my query, B2 is a valid date in date format. Column O has some cells that are text strings and others that are valid dates; I have set the format of the entire column to "Date".
Here is a link to a simple example, feel free to play around with the query: https://docs.google.com/spreadsheets/d/1O4ms9ufvZ_CRLl_LG45hksjRoOJtv0XexbfjCLqFW4I/edit?usp=sharing
See if this works?
=filter('SheetName'!A3:A, 'SheetName'!O3:O=B2)
correct syntax should be:
=ARRAYFORMULA(QUERY(TO_TEXT(SheetName!$A2:$S),
"select Col16 where Col15 = '"&TO_TEXT(DATEVALUE(B2))&"'"))

IsDate ArrayFormula

Have just noticed isDate does not work in arrayformula.
Case
Want to filter all values if dates:
Used the formula:
=FILTER(data,ISDATE(data))
Expected result:
8/28/2018
Got:
#N/A
Question
Why? Other checks work in filter (isNumber, isText, isErr).
Workarounds?
Please try:
=ARRAYFORMULA(ISDATE_STRICT(A1:A11))
The function is currently not documented.
🧐: ISDATE_STRICT wont let date&time format, dates only
Do not know the reason, still curious.
Workaround: =FILTER(data,IFERROR(DATEVALUE(data))) was found here
Note: Workaround will NOT work for dates formatted as:
dd.mm.yyyy
You may use a duck-typed workaround:
=FILTER(data,REGEXMATCH(MID(data,7,4),"20\d{2}"))
Will check if formatted date has a 20XX year string inside.
Now you can convert any formula to arrayformula:
=BYROW(A2:A12,LAMBDA(r,ISDATE(r)))
A workaround that could work depending on what you're trying to do as far as Arrayformula is concerned
=ARRAYFORUMLA(ISNUMBER(VALUE(data)))
VALUE can turn the time into a number
ISNUMBER checks if it's a number
ISNUMBER works fine within ARRAYFORMULA

Exclude dates from a range in google spreadsheets

I am new to google spreadsheets & trying to exclude dates from a range in google spreadsheet in following way.
I have following cells in range (c2:c7):
4/9/2015 9:21:09
4/9/2015 17:50:24
4/10/2015 17:25:57
4/11/2015 17:07:00
4/13/2015 18:13:35
4/14/2015 17:00:58
I want to exclude all dates and want following range in B2:
9:21:09
17:50:24
17:25:57
17:07:00
18:13:35
17:00:58
I have tried using regexextract function but could not succeed, can anybody help please, I have mentioned this in following link:
https://docs.google.com/spreadsheets/d/1tsmeLz_TZ_nm_1M40bzM7cKq9mU_FUeFxdsk0fnL6wo/edit#gid=0
try:
=ArrayFormula(mod(C2:C7,1))
where C2:C7 is the range with the timestamp. Format the column with the output as TIME (via the 123-button)
Use a regex.
/(two numbers):(two numbers):(two numbers)/
After pulling each of these parts from the dates, save them into an array and set them in column B. (It's preferred to copy to a 2D Array then use Range.setValues() for speed).
This works:
=TEXT(A1,"HH:MM:SS")

Resources