Combining date/time and maintaining number formatting - google-sheets

I am using an array formula and IMPORTRANGE to import and combine a date column and time column from another sheet:
=ARRAYFORMULA(IMPORTRANGE(BG1, "FORM-SORT!V:V") & CHAR(10) & (IMPORTRANGE(BG1, "FORM-SORT!W:W")))
The first range is my date column and the second is my time column. The data is importing and combining properly, however neither the date nor time is formatting correctly, they are displaying integer values and will not respond to any number formatting options.

Please try:
=ARRAYFORMULA(text(IMPORTRANGE(BG1,"FORM-SORT!V:V"),"dd-mm-yy")&CHAR(10)&TEXT(IMPORTRANGE(BG1,"FORM-SORT!W:W"),"hh:mm"))

Related

Using a date in a cell in Sheet1 as a value for a filter in a Countifs formula for values in the date range on another sheet

I'm trying to use a formula in Google Sheets to use the date values of cells in Sheet1 (a27 and b27) as the Date references for the date range in the coutifs formula below.
=countifs('Sheet2'!$C:$C,">=01/10/2023", 'Sheet2'!$C:$C,"<=01/17/2023",'Sheet2'!$D:$D,"Apples")
This initial formula works fine, where I am trying to count how many instances of "apples" occurred in a specific date range on Sheet 2 (1/10/2023-1/17/2023).
As you can see, the dates on Sheet 2 are in column C, and the instance of "Apples" would be in column D.
However, I am trying to find a way to pull the data from Sheet2 to Sheet1 using date references in 2 cells in Sheet1. 'Sheet1'!a27 has the date value for 1/10/2023, and 'Sheet1'!b27 has the value for 1/17/2023.
I would like to be able to use the Sheet1 a27/b27 placeholders instead of manually going in and entering dates into the formula.
I have tried the string below, hoping it would pull the date values from Sheet1 a27&b27 automatically to be the date of reference for the countifs formula from Sheet2.
While it is not causing an "error", it is not pulling any numbers at all.
=countifs('Sheet2'!$C:$C,">='Sheet1'!a27", 'Sheet2'!$C:$C,"<='Sheet1'!b27",'Sheet2'!$D:$D,"Apples")
Please note that Sheet2 column C and Sheet1 columns b&c already have the number formats set to "date".
try:
=COUNTIFS(Sheet2!C:C, ">="&Sheet1!A27,
Sheet2!C:C, "<="&Sheet1!B27, Sheet2!D:D, "Apples")

Google Sheets date calculation

Is there a way to take a date in one row and auto calculate another date in another column 10 days out?
ex: (column a) 12/11/20 -auto calculate the date 10 days from then
and put in (column d) 12/21/20.
So anytime I enter a date and need the 10 day out date it just auto calculates so I don't have to keep entering the date over and over again.
This is possible by using ARRAYFORMULA().
ARRAYFORMULA enables the display of values returned from an array formula into multiple rows and/or columns and the use of non-array functions with arrays.
Try this: =Arrayformula(TO_DATE(IF(A1:A="","", A1:A+10))).
Example:
Reference
Arrayformula()

Why does a different result show up when filtering a date in google sheets?

I'm very new to programming so I'm not sure how to phrase this but in google sheets, I'm having a problem:
when filtering results using =IFERROR(FILTER('Segment Management'!B:B,'Segment Management'!A:A=B5)), it works perfectly fine with letters and numbers but when there's a date in Segment Management cell B5 it instead of saying the date (in this case 15/3/2020) it outputs "43906". Could I get some help to explain why it says this number instead of the date?
Date is considered as plain number in google sheets that's the reason you get numbers instead of date you can either do either of one
Select the column where you have put formula & in menu Format> Number> and select date formatting
OR
use this formula =ARRAYFORMULA(TEXT(FILTER('Segment Management'!B:B,'Segment Management'!A:A=B5),"DD/MM/YYYY"))

When using SUMIF function, is there a way to accept timestamp values (e.g. 2/12/2019 19:56:16) as the range to test against the criteria?

I'm working with two columns,
column A: a list of timestamps
column B: a list of numbers
I'm trying to use the sumif(range, criteria, [sum range]) function to check if the month in column A is January, and so on for all months.
The issue is that I need a way to either convert the range for the sumif to month names, or use criteria other than a string (because a timestamp isn't going to ever be "=January".
My thought was that I could do either
=sumif(TEXT(TO_DATE(A2:A),"mmmm"), "=January", B2:B)
or
=sumif(A2:A, TEXT(TO_DATE(A2:A),"mmmm")="January", B2:B)
these are more or less pseudo-code, I'm trying to convey my thought process
I understand I could create a new column that converts the timestamps into months, but is there anyway I can preform this sumif, without having to make a new column?
Using SUMIFS, with dates you set the extents, this works in excel and google sheets:
=SUMIFS(B:B,A:A,">=" & DATE(2019,1,1),A:A,"<" & DATE(2019,2,1))
With Google Sheets you can also use filter:
=SUM(FILTER(B:B,MONTH(A:A)=1))
"=2" = February, "=3" = March, etc.
=ARRAYFORMULA(SUMIF(MONTH(A2:A), "=2", B2:B))
if you want to select it from a drop-down menu use:
=ARRAYFORMULA(SUMIF(MONTH(A2:A), "="&MONTH(F2&1), B2:B))

QUERY using cell contents as SQL variables

Here is what the spreadsheet I'm working with looks like:
Summary table
(top of sheet)
Source data
(same sheet, below output)
I'm using the QUERY function to populate the appropriate feeds in the summary table with the data starting at A24 needs to be placed into.
Here is the formula I'm using in cell C6 (similar formulas are used throughout the summary table):
=QUERY($A$24:$D$57, "Select D Where B='ENQ' and A='2/27/14 - Thu'")
This gets the right information, but the formula needs to be edited to be unique in each cell it's used in. The problem being unable to quickly populate the cells with A='2/27/14 - Thu' being too specific.
I was trying to set it up so that:
date in A would compare with dates found on headers in ROW 2 before accepting data
room type in B would compare with value from A in each row of the summary table
How can the QUERY function be written to refer to these values as variables, instead of using the literal strings in my original function?
Instead of fixed strings such as 'ENQ', you can have your formula refer to the index in column A of your output. For example, you could change your formula to this, in cell C4:
=QUERY($A$24:$D, "Select D Where B='" & $A4 & "' and A='2/27/14 - Thu'")
^^^^^^^
The ampersand (&) is used to concatenate string segments.
Note that since the source data extends to the bottom of the data range of the sheet, we can forego specifying the bottom row. The range $A$24:$D will take in all rows, so it will automatically adjust to additional source data.
To compare dates, both values need to be dates. "2/27/14 - Thu" is not recognized as a date in your source data sheet, but as text, even though you've set the numeric format to date. So make sure you change all your source data to have actual dates in column A.
You can still have your dates formatted the way you like - see this screenshot. The content of A2 is now a proper date, "2/27/2014", but the format is set to display "mm/dd/yy - DDD". As long as the data is a date, the query can be built using the spreadsheet TEXT function to interpret the date in its yyyy-mm-dd format.
With dates in your source column, you can use todate() scalar function to tell QUERY to convert the date in the source to a query-date, and the date keyword to treat the following literal string (from C2) as a date.
The resulting function for cell C4 is:
=QUERY($A$24:$D , "Select D Where B='" & $A4 & "'and todate(A) = date '" & TEXT($C$2,"yyyy-MM-dd") & "'")
^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Similarly, for D4:
=QUERY($A$24:$D , "Select C Where B='"&$A4&"'and todate(A) = date '"&TEXT($C$2,"yyyy-MM-dd")&"'")
Your calculations in column E can be improved to handle #N/A results appearing in columns C or D:
=if(isna(C12*D12),0,C12*D12)

Resources