Query and exclude empty cells - google-sheets

I'm trying to query data, format it, and exclude empty cells.
=ARRAYFORMULA({"Date";IFERROR(QUERY({text(J2:J, "m/d/yyyy")}))})
Currently using this.
Tried using this:
=ARRAYFORMULA({"Date";IFERROR(QUERY({text(J2:J, "m/d/yyyy"), "where J <>''"}))})
But cells don't fill.
Not sure what I'm missing.

If you data in J Column are true date then you can use below QUERY() formula.
=QUERY(J2:J,"select J where J is not null label J 'Date' format J 'm/d/yyyy'")
Edit: If data is string formatted then could try-
=ArrayFormula(QUERY(DateValue(J2:J),"select Col1 where Col1 is not null label Col1 'Date' format Col1 'm/d/yyyy'"))

Related

GoogleSheets SumIFS in array formula

I'm trying to convert my Sumifs formula into an array formula
(so that the sheet auto updates)
I'm struggling to do so though
I tried using sumif formula and combining the columns, but I can't get it to work right.
I created this simplified version of my data
https://docs.google.com/spreadsheets/d/1qnoY_MZTup8XLLWCu61-Ifiv8dak6QRc1CxsGKpmFWE/edit?usp=sharing
(I know there's only two rows, but in my actual data there's a lot more and the number of brands vary)
I've shown in column C on sheet 2 how the sumifs formula works.
But ideally I'd like an array formula in cell B2 that will populate all the rows for me (instead of having to fill down the sumifs each time)
No need to use arrayformula for this. You can simply use query:
Formula (A2):
=query({Sheet1!A2:D}, "select Col1, sum(Col4) where Col1 is not null and Col2 is null and Col3 is null group by Col1 label sum(Col4) ''")
This will populate both A and B.
Output:

Why does QUERY not read empty cells as 0 in arithmetic functions? And what can I do about it?

The query function calls a range {A:C} where either B or C contains a value while the other an empty cell.
The range is compiled by a script that writes enters the values in rows. I can make the script enter a 0 instead of '', but I want to understand this, and it seems a bit to fragile. It has no effect on when I format the empty cells as numbers.
When my QUERY function in another document calls this range as ...A:C";"select Col1, Col2-Col3") it returns Col1 (A) but no second column, unless I enter a 0 in an empty cell in {A:C}, then that row is calculated by the Query function.
Can I solve this in another way, other than replacing empty cells with 0?
You can convert empty strings to 0s with --(...) while passing the range to the QUERY, numbers will remain as is:
=QUERY(
ARRAYFORMULA({A:A\ --(B:C)});
"SELECT Col1, Col2 - Col3
WHERE Col1 IS NOT NULL
LABEL Col2 - Col3 ''
";
0
)

Search for lowest/highest value in the date array

What is the best formula to get the lowest and highest values from column C for every date?
Need to fill F and G columns as a result
Link:
https://docs.google.com/spreadsheets/d/1IxLit5vOf9FIjEp4TOEWLFNoCB4yS5mYXXMXo2tvtiM/edit?usp=sharing
try:
=ARRAYFORMULA(QUERY({LEFT(A2:A; 10)*1\C2:C};
"select Col1,min(Col2),max(Col2)
where Col2 is not null
group by Col1
label Col1'date'"))

How to use ARRAYFORMULA in query where clause?

In cell C1:C of my table I got 6 rows with ticket id's. I like to search different spreadsheets to search for those ticket id's and calculate the total hours spent on that ticket.
I have it working using the following formula:
=QUERY({IMPORTRANGE("SPREADSHEETID";"B3:B")\ARRAYFORMULA(TO_PURE_NUMBER(IMPORTRANGE("SPREADSHEETID";"F3:F")-IMPORTRANGE("SPREADSHEETID";"E3:E")))};"SELECT SUM(Col2) WHERE Col1 = '"&C1&"' GROUP BY Col1 LABEL SUM(Col2) ''")
In this example, C1 is where the ticket ID can be found.
Now I thought I could just wrap QUERY in a ARRAYFORMULA and use C1:C instead of just C1 but that won't work. Now I could just copy and paste the above formula in every cell but there must be a cleaner way.
ANSWER
I used the following formula to make it work, thanks to Max's answer below.
=QUERY(
{
IMPORTRANGE("SPREADSHEETID";"B3:B")\
ARRAYFORMULA(
TO_PURE_NUMBER(
IMPORTRANGE("SPREADSHEETID";"F3:F") - IMPORTRANGE("SPREADSHEETID";"E3:E")
)
)
};
"
SELECT Col1, SUM(Col2)
WHERE Col1 = '" & JOIN("' OR Col1 = '";FILTER(C:C; C:C <> "")) & "'
GROUP BY Col1
LABEL SUM(Col2) ''
")
Sample formula is:
=QUERY({A:B},"select * where Col1 = '"&JOIN("' or Col1 = '",FILTER(D2:D,D2:D<>""))&"'")
No, one cannot create an array of query strings and use arrayformula(query(...)) to run them all at once.
Alternative: instead of
SELECT SUM(Col2) WHERE Col1 = '"&C1&"' GROUP BY Col1 LABEL SUM(Col2) ''
use the query
SELECT Col1, SUM(Col2) GROUP BY Col1
elsewhere on the sheet, and then use vlookup to look up the sum for each value of Col1 that you want. vlookup can be used inside of arrayformula like this:
=arrayformula(vlookup(C1:C10, E:F, 2, 0))
looks up each of values in C1..C10 in the column E (exact match required) and returns the corresponding value in column F (2nd column of the searched range).

Query help. Remove rows where duration equals zero

I have a list of results which include a column with duration time. I want to exclude any rows where the duration is zero. I tried the following without success.
not M contains '00:00:00.000'
M > 0
not M contains '12:00:00 AM'
I suspect it has something to do with the way the duration is formatted in the uploadData!A:M sheet. Here's the formula in question and the spreadsheet in question.
=query(uploadData!A:M,"Select B, C, H, I, M where not(C) contains '"&JOIN("|",filter!A:A)&"' and B contains 'Incoming' and not B is null and not H is null ",1)
Figured it out! I just used a FILTER function to remove the zero durations before wrapping it with a query. You'll notice I had to change the column references from letters to numbers to get it to work correctly.
=query(FILTER(uploadData!A:M,uploadData!M:M>0),"Select Col2, Col3, Col8, Col9, Col13 where not Col3 contains '"&JOIN("' and not Col3 contains '",filter(filter!A2:A,filter!A2:A<>""))&"' and Col2 contains 'Incoming' and not Col2 is null and not Col9 is null Order by Col13",1)

Resources