Google Sheet Query Function Issues - google-sheets

I have a good working Query function except for a few cases where its calling from and searching from variables on my data sheet.
=QUERY(detailedManifest,"SELECT K, J, SUM(H) WHERE C = '"&A3&"' AND K <> 'SAMPLES' GROUP BY J, K ORDER BY K LABEL SUM(H) ''", 0)
It works on everything except when A3 = Bacon's Buds or Bella Jane's
I believe it's because there is ' in the name.
Is there a work around that would allow the name to be as is and still work within the Query function?

=QUERY(detailedManifest,"SELECT K, J, SUM(H) WHERE C = """&A3&""" AND K <> 'SAMPLES' GROUP BY J, K ORDER BY K LABEL SUM(H) ''", 0)
Just had to change my '"&A3&"' to be """&A3&""" and this allowed the names
Bacon's Buds and Bella Jane's to work correctly within the query! YAY

Related

How to sum by category in Google Sheets and manipulate the result?

I have this format:
A B C D
invoice date product amount
D1 P1 10
D1 P2 100
D1 P1 10
I1 D1 P1 10
I want to calculate the sum of non-invoiced products by product. I'm almost there with this:
=query($A$2:$D;"select C, sum(D) where A is null group by C")
sum
P1 20
P2 100
But I actually want to split this result (ignoring the "sum" header) and put it into two non-adjacent columns E and G:
E F G
row1 P1 20
ro22 P2 100
I guess I could write two separate array queries, one for E1 and another for G1, but I'm still not sure how to extract pieces of the QUERY result (and there might be a simpler approach than using QUERY).
Live example
Unfortunately, ignoring columns in a formula is not possible. You need to create 2 QUERY functions.
Try these formulas:
For cell E8: =QUERY(QUERY(A2:D5, "SELECT C, SUM(D) where A is null group by C label SUM(D) ''"), "SELECT Col1")
For cell G8: =QUERY(QUERY(A2:D5, "SELECT C, SUM(D) where A is null group by C label SUM(D) ''"), "SELECT Col2")
Example:
Reference:
QUERY

How to write a conditional query formula?

I have a query in google sheets:
=QUERY('Depot Report'!D:Q, "SELECT I, J WHERE P ='"&AK4&"'")'
AK4 is a data validated list of numbers 1-40 which selects all I, J based on the value of AK4.
What I want is "all" in the list that will run the query:
=QUERY('Depot Report'!D:Q, "SELECT I, J")
Edit after your comments
The formula always work very well, but your problem in your sheet is:
Values in column P are not numbers because are formatted as text.
No problem. Solution is very easy.
SOLUTION
Select all column P and format from menu Automatic.
Also I changed formula a little for cell S12 for exactly what you need.
Only copy/paste formula now.
.
=QUERY('Depot Report'!D2:Q, "SELECT I, J WHERE 1=1"&IF(T4="All",""," AND P= "&T4&" "))
Use this formula
=QUERY('Depot Report'!D2:Q, "SELECT I, J WHERE 1=1"&IF(AK4="",""," AND P= "&AK4&" "))

Multiple Google Sheet queries break when one of them returns "no data"

I have a problem where if one QUERY statement (in a group of multiple) return "no data", it breaks the entire formula. Here is a quick video showing this in action:
https://www.dropbox.com/s/pud4zmjqopdqim5/shopping-list-explanation.mov
I have tried to wrap each query with IFERROR, for example:
IFERROR(QUERY('Step 2 - Snacks'!E:H, "select E,F where G = 'M' AND F > 0 AND H = 'Y'",0),0)
..but I still have the same issue.
I would like a solution where if any QUERY returns no data, then it is just ignored, but after a bunch of hours I am nearing the end of my tether and would appreciate some tips.
Update: Here is the Google sheet (shared with anyone who has the link)
Thanks!
Not tested, but where the query returns an error, try to place empty values for every column in the query.
=IFERROR(QUERY('Step 2 - Snacks'!E:H, "select E,F where G = 'M' AND F > 0 AND H = 'Y'",0),{"", ""})
Then, when you have multipled queries stacked, wrap an 'outer' query around everything filtering out the empty rows. Something like:
=QUERY( IFERROR(QUERY('Step 2 - Snacks'!E:H, "select E,F where G = 'M' AND F > 0 AND H = 'Y'",0),{"", ""}); IFERROR(QUERY(....), {"", ""}), "where Col1 <> ''")
Hope that helps?

Improve Query Function in Google Sheets

I've been using the following function:
=query(Sheet1!A2:D," select A, B, C where A matches '"&JOIN("|", A2:A)&"' and D matches 'yes'")
Is there anyway that I can make is so that every row that starts with a match will be added a comma separated list in which each column occupies one cell with no duplicates as shown in sheet3.
https://docs.google.com/spreadsheets/d/1YDxIUnZzzYde9hcexPoDegv4HBuiUwk2wLKSXazu9hE/edit?usp=sharing
Sheet 2 has the function that I used and the result.
It is not entirely clear what you want to do, but try this. In Sheet1 in E2 put this combining Col A and D:
=arrayFormula(A2:A & if(isBlank(D2:D),""," ") & D2:D)
In F2 combine Col C and D with this:
=arrayFormula(B2:B & if(isBlank(C2:C),"",",") & C2:C)
In G2 find the unique values from Col F with this:
=UNIQUE(E2:E)
In H2 put this and drag the formula down:
=join(",",query(E2:F,"select F where E contains '"& G2 &"'"))
Hide Cols E & F

Filter out phone numbers from Google Sheets query using regexreplace?

I have a list of number using this query formula.
=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)
You can see I'm trying to filter the results so as to NOT include any matching numbers found in filter!A:A. However, it doesn't like the fact that the result and filter sheet use the telephone number format (###) ###-####.
I believe using regexreplace will help resolve this issue but I'm not knowledgeable enough with regexreplace to know how to incorporate it.
Can anyone tell me how I can achieve this?
I'm not sure, google sheets query understand pipes | as OR logic, so you may rty this formula instead:
=query(uploadData!A:M,"Select B, C, H, I, M where not C contains '"&JOIN("' and not C contains '",filter(filter!A2:A,filter!A2:A<>""))&"' and B contains 'Incoming' and not B is null and not H is null ",1)
I used JOIN("' and not C contains '",filter(filter!A2:A,filter!A2:A<>"")):
join + "' and not C contains '" to get all conditions one by one
filter(filter!A2:A,filter!A2:A<>"") to have only not empty cells

Resources