=QUERY(IMPORTRANGE(Data),"SELECT Col1,Col2,Col3,Col4")
I have a simple formula of the format above. The data inside importrange() is in another Google Sheets file.
However, within this particular file I have the QUERY() formula in, I would like to refer to cells in another sheet and use these to create columns inside query.
Before the Col1 inside QUERY() above, I need two separate columns:
PO, Supplier
Where PO is (in normal formula format): "PO-"&Control!A6&"-"&Control!A5 (this is basically text string "PO-" combined with Control cell A6, text string "-" and Control cell A5)
and supplier is simply Control!A6.
How can I amend these two so they are columns within QUERY()?
example could be:
=QUERY(IMPORTRANGE(Data),
"select Col1,Col2,Col3,Col4
where Col1 = 'PO-"&Control!A6&"-"&Control!A5&"'
and Col2 = '"&Control!A6&"'", )
Related
I have a google sheet, wherein the first two columns are filled using "Arrayformula" from a pivot table. Is it possible to merge some of the cells in first column while using Arrayformula.
Below is an image of sample data which I am obtaining from the pivot. I would like to have "Porsche" from 1st column to be text wrapped for all its corresponding customer IDs.
https://i.stack.imgur.com/Pdt4I.png
Thank you
You can try using query to filter out rows where there are no Customer IDs.
Formula:
=arrayformula(query({A1:B}, "where Col2 is not null"))
Output:
If this isn't the one you want, kindly provide your expected result as I'm unsure with how you used the term "text wrapped"
I am interested in creating a string of headers for a rows based on which columns are marked true (sample spreadsheet linked below)
The following formulas both return the desired result for Row 2:
=JOIN(", ",QUERY(TRANSPOSE($B$1:$G),"select Col1 where Col2 = TRUE",0))
=JOIN(", ",FILTER($B$1:$G$1,B2:G2=TRUE))
I am unable to successfully use an ARRAYFORMULA with either option. Both require the current row to be selected: QUERY in "where Col#" of query syntax and FILTER in the range for the condition syntax.
=ArrayFormula(IF(A2:A<>"",JOIN(", ",QUERY(TRANSPOSE($B$1:$G),"select Col1 where Col"&ROW(A2:A)&" = TRUE",0)),""))
=ArrayFormula(IF(A2:A<>"",(JOIN(", ",FILTER($B$1:$G$1,B2:G2=TRUE))),""))
The linked sheet below shows the desired result in COLUMN H & COLUMN J (these were updated individually. The ARRAYFORMULA options are in COLUMN I & COLUMN K (currently not working).
I am interested in a solution that can populate the desired results without requiring each row to be updated individually.
link directly to "headers" tab:
https://docs.google.com/spreadsheets/d/1E7EGjK-YuVBxgdX5URnzZMDOwvF6oAi7ZJxY9HmySNc/edit#gid=966778061
In H2 try
=ArrayFormula(if(len(A2:A), regexreplace(trim(transpose(query(transpose(if(B2:G, B1:G1&", ",)),,rows(A2:A)))), ",$",),))
and see if that works?
Below is my query function in its original form:
=ArrayFormula(query({importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","CPG!A2:L20");importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","PUB!A2:L20")},"Select Col5, Sum (Col4) where Col6='' group by Col5 pivot Col7"))
Which I am trying to shorten the formula by using indirect to refer to concatenated import ranges by the following attempt
=ArrayFormula(query(indirect("JOIN!J3"),"Select Col5, Sum (Col4) where Col6='' group by Col5 pivot Col7"))
but come up with this error:
Error
Unable to parse query string for
Function QUERY parameter 2:
NO COLUMN: Col5
The Join!J3 cell contains the value below:
{importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","CPG!A2:L20");importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","PUB!A2:L20")}
I research various similar question in forums but their answers comes to no solution. Usually it is to use "Select Col1" instead of "Select A" but my formulas are all using Col1, Col2 already. Am doing anything wrong?
I have included some images for further clarification.
The original formula:
The shortening attempt:
The cell value in sheetname: JOIN cell: J3:
The cell value in J3 is actually a pasted value from cell A1:
If I understand correctly, because your formula is now referring to a specific range in the sheet instead of an array of ranges, you will need to use A, B instead of Col1, Col2, etc.
I assume the data produced by cell J3 in the sheet JOIN displays data in J3:U21 (based on the range A2:J20). You need to query all of this, not just the cell containing the formula.
Try the formula below.
(I have made assumptions about what columns the data sits in--please amend where necessary).
=ArrayFormula(query(indirect("JOIN!J3:U21"),"Select N, Sum (M) where O='' group by N pivot P")
EDIT: You seem to be using the same range and ID. You can refer to them using just two cells.
={IMPORTRANGE(D6,"SheetName1"&E6);IMPORTRANGE(D6,"SheetName2"&E6)}
I have a Google Sheets document with four sheets. In each sheet, there are two columns: first is a name, and second a value.
I need to get the total of the values from the four sheets in a fifth sheet where the names from the four name-columns correspond.
The column with the values is called differently in most sheets.
How can I accomplish this task?
You can use Query + Arrays, like on image below:
Code:
=QUERY({Sheet1!A2:B;Sheet2!A2:B;Sheet3!A2:B;Sheet4!A2:B};
"select Col1,sum(Col2) where Col1 is not null group by Col1 label Col1 'Name',sum(Col2) 'Total'";0)
Explanation:
First: you combine 4 sheets using an Array. Ranges start from row 2 to omit different columns headers:
{Sheet1!A2:B;Sheet2!A2:B;Sheet3!A2:B;Sheet4!A2:B}
Second: Using Query to perform a total. In Query there are some extra operations:
Col1 is not null - for not showing empty rows in totals
label Col1 'Name',sum(Col2) 'Total' - for naming result columns
Syntax may be a little different depending on your local settings, so look at the working copy:
Link to working copy
Is that serves your needs?
I have two sheets of data, the second sheet is "DATA".
The primary sheet I'm using, I have a =query() to query the other sheet based on a month number. From my research, I found this - https://www.benlcollins.com/spreadsheets/query-dates/ - which by itself, does work, but within query(), doesn't work.
Data:
1/1/18 2/1/18 3/1/18 4/1/18
Broken function:
=IFERROR(QUERY(DATA!$A:$L, "Select sum(G) WHERE B contains lower('"&$A4&"') AND MONTH(A)+1='"&TEXT(DATEVALUE(C1),"m")&"' label sum(G) ''"),"$0")
Working function:
=IFERROR(QUERY(DATA!$A:$L, "Select sum(G) WHERE B contains lower('"&$A4&"') AND MONTH(A)+1=4 label sum(G) ''"),"$0")
Problem...is that I want it to be dynamic.
When I use
'"&TEXT(DATEVALUE("1/1/2000"),"yyyy-mm-dd")&"'
as a function, it renders as a "4" which is what the query() is looking for.
What about something like
=IFERROR(QUERY(DATA!$A:$L, "Select sum(G) WHERE B contains lower('"&$A4&"') AND MONTH(A)+1= "&MONTH(C1)&" label sum(G) ''"),"$0")