Query and match data in multiple tabs of 1 Google Sheet - google-sheets

I have two tabs that list names along with other data. I would like to query "Leads Weekly" A:E and have that data pull the value of column E where A matches C on another Sheet. ?
I've tried query formulas : =QUERY('Leads weekly'!A:E, "Select E where A contains 'MELISSA SURO'")
which works, but I'm looking for something scalable, I have over 500 names I would have to type in.

try:
=QUERY('Leads weekly'!A:E,
"select E where A matches '"&TEXTJOIN("|", 1, Sheet!C:C)&"'", )

Related

Google Sheets Query - Multiple Select Statement If Condition

Currently, I have a worksheet in Google Sheets that uses the formula:
=query('Form Responses 1'!A2:AC,"Select A,B,D,L,M,N,O,P Where L is not null")
This selects the columns A,B,D,L,M,N,O,P Where L is not null but if L is null, I want to select the columns A,B,D,Y,Z,AA,AB,AC instead.
So far, I've tried both of the following:
=query('Form Responses 1'!A2:AC,"Select A,B,D,L,M,N,O,P Where L is not null" AND "Select A,B,D,Y,Z,AA,AB,AC Where Y is not null")
=query('Form Responses 1'!A2:AC,"Select A,B,D,L,M,N,O,P Where L is not null" OR "Select A,B,D,Y,Z,AA,AB,AC Where Y is not null")
Answer
The following formula should produce the result you desire:
=ARRAYFORMULA(IF(ISBLANK(L2:L),{A2:A,B2:B,D2:D,Y2:Y,Z2:Z,AA2:AA,AB2:AB,AC2:AC},{A2:A,B2:B,D2:D,L2:L,M2:M,N2:N,O2:O,P2:P}))
Explanation
First, the =ISBLANK function is used to check whether the value of column L is empty or not. This creates an array of boolean values which are fed into the =IF function. Depending on the result of =ISBLANK one of two possible sets of columns are selected.
Everything is contained within =ARRAYFORMULA so that it functions properly across many rows.
Functions used:
=ISBLANK
=IF
=ARRAYFORMULA

GS Query to split a column (Last, First) into 2 columns

I have a 'Raw Invoice' tab which is an excel file copy/pasted directly over. I'm then trying to format the data in the 'Invoices' tab in that column order using a query. I need to be able to break out the Student Name into two separate columns, hopefully within the query itself. Preferably it would then change it so column C is Last Name and column D is First name and the rest of columns shift over one.
I don't know if there's a way to perform a SPLIT function within the query. Right now I'm using a clunky method by doing a VLOOKUP on the student ID to get the names from another tab (not included in the Sample GS cuz it's an importrange from a work file), but it then creates two separate queries. Ideally I can somehow split column C within one query, but am getting lost by nesting queries and arrays together. I might be able to use REGEXEXTRACT, but again get lost in where to put it in the query or whether that's overkill.
QUERY('Raw Invoice'!$A:$I,"Select F,B,A, 'Bobs Diner',D,G,I where C is not null label 'Bobs Diner' 'Company' Format F 'M/DD/YYYY' ",1)
Link to sheet.
split in query arguments is not possible but you can do:
=ARRAYFORMULA(QUERY({IFERROR(SPLIT('Raw Invoice'!A:A, ", ")), 'Raw Invoice'!B:I},
"select Col7,Col3,Col1,Col2,'Bobs Diner',Col5,Col8,Col10
where Col3 is not null
label 'Bobs Diner' 'Company'
format Col7 'M/DD/YYYY'", 1))
Wat I suggest is to implement in Row Invoice
=arrayformula(split(A3:A,","))
and then
=QUERY('Raw Invoice'!$A:$K,"Select F,B,J,K, 'Bobs Diner',D,G,I where C is not null label 'Bobs Diner' 'Company' Format F 'M/DD/YYYY' ",1)

Google Sheet Filter formula based on range of cells

I've got some data
Basically a list of Items
and another sheet that contains a list of orders
(Some items can appear in multiple orders, which is why I can't use a vlookup for this)
My problem is I want to get the ALl the Order IDs of all items in dynamic list(in my example there's only 3 items, but that can grow.
I'm trying to use the filter formula and have got this so far:
=filter('Orders'!AC1:AD,'Orders'!K:K=A4)
which works fine at retrieving all the Order ID's for the item number in cell A4.
But I want the Order ID's for all the Items in column A.
I tried
=filter('Orders'!AC1:AD,'Orders'!K:K=A2:A)
But that doesn't work. I'm guessing I need to do some kind of array formula maybe.
But I can't figure it out.
You can use the QUERY function
This is a SQL like syntax to manipulate your data.
=query({Orders!$A:$B},"select Col2 where Col1 matches '"&textjoin("|",true,unique(Summary!$A4:$A))&"' ",1)
or this if you need to sort the result:
=query({Orders!$A:$B},"select Col2 where Col1 matches '"&textjoin("|",true,unique(Summary!$A4:$A))&"' order by Col2 ",1)
The first argument is the range that you want to query. Which in this case is inserted with the array notation {Orders!$A:$B}.
The next argument is a string representing an SQL like statment that in this case says "Select column 2 when column 1 matches Item A or Item C or Item D".
The "Item A or Item C or Item D" part is constructed with another formula, TEXTJOIN. Just grabbing the range to join and the delimiter is set to the OR operator which is |.

Google Sheets query Select column concat with Select Count column

I help manage loot for a group in an MMO. I've created a google sheet to maintain visibility into who needs what items. The sheet basically works the way i want, but i'm having some trouble with returning SELECT A concatenated with SELECT COUNT(A). Honestly, i'm not sure how to go about it, but this is what i've got:
Right now I'm transposing
SELECT A WHERE C CONTAINS <VALUE>
which returns like this for multiple results:
Name OtherName OtherName
Meanwhile, the values (but not the format) i want to return, i can get with :
SELECT A, COUNT(A) WHERE C CONTAINS <VALUE> GROUP BY A LABEL COUNT(A) ''"
which returns:
Name OtherName
1 2
The desired output is:
Name(1) Othername(2)
The sheet is here:
https://docs.google.com/spreadsheets/d/1HUcgVg2ZFHteXhRnk2W2j_9RU4RvMd7nMTqCuRgmUdo/edit?usp=sharing
And the queries in question are on Sheet1. I put some example queries I've tried also in the sheet.
try:
=INDEX(REGEXREPLACE(QUERY(TRANSPOSE(IFNA(IF(B11>0, QUERY(GearList!A:C,
"select A,count(A)
where C contains '"&$D11&"'
group by A
label count(A)''", 0)), )),,99^99), " (\d+)", "($1)"))

Query returning error Unable to parse query string for Function QUERY parameter 2: NO_COLUMN

I am currently working in the following spreadsheet
https://docs.google.com/spreadsheets/d/13KfjUhWSB-BjGyC1G8f8i8o4SPd1kFFLkjN7D6VY8Lk/edit#gid=993210576
In which I am importing data from another worksheet using IMPORTRANGE, and writing a QUERY to match the cells in column B, which correspond to a specific part number, to their corresponding cut quantity found in Column D of the imported sheet. The query I have written is as follows.
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28/edit#gid=473793446",
"FABRICATION LOG!A78169:K"), "Select Col3 where Col4 = "&B3&" limit 1", 0)`
And is returning the error message:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: WFR332703
I have used ImportRange for the sheet I am linking to in sheet1 of the spreadsheet linked above, and allowed access, so the error is not there.
Sheet1 is there to display the values returned for the IMPORTRANGE so that I can manually look up values I am expecting to get. Now for some of these cells, I expect to not get a value, as these will not be in the sheet I'm importing. But for others, I am expecting a numerical value, which is not being returned. I suspect this may have something to do with the fact that there is a mismatch between Datatypes since the entries in column b are both letters and numbers, but this is only a hunch with no actual facts to back it up. If anyone has any suggestions It'd be greatly appreciated.
first, paste this into some cell and connect you sheets by allowing access:
=IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28", "FABRICATION LOG!A1")
then use the formula:
=QUERY(IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28",
"FABRICATION LOG!A78169:D"),
"select Col3
where Col4 = '"&B3&"'
limit 1", 0)
if cell B3 is number use:
=QUERY(IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28",
"FABRICATION LOG!A78169:D"),
"select Col3
where Col4 = "&B3&"
limit 1", 0)
I came here because I had a query like:
=Query(Data, "select * where i < 70", 1)
What fixed it was changing to:
=Query(Data, "select * where I < 70", 1)
The column in the where clause needs to be upper case if its a letter higher than 'd'.

Resources