Query across multiple columns within one sheet - google-sheets

I am currently working to build a query from a Google sheet that will allow me to grab data from two different ranges of cells, my example is below:
=query('Form Responses'!A2:F,G2:G "Select * Where F='Yes'")
This does not work...
I want to grab data from A2:F AND G2:G within the same sheet, Form Responses.... how do I go about doing that?

you need to do it like this:
=QUERY('Form Responses'!A2:K, "select A,B,C,D,E,K,G where F='Yes'")

Related

sum SQL in google sheet query function doesn't add

I have been working on a sheet for a while and I would like to use the query function of google sheet for adding the amount of the ingredients of different meals, to create an 'overall' shopping list, but it seems to be that the numbers are not added together.
I have created an example sheet of the problem to spare you from the unrelevant details, here is the link for that: https://docs.google.com/spreadsheets/d/1BHhs9XG5kX-o8pR27L64qAQ08c93bAy1g3YKNI073vY/edit?usp=sharing
Can you help me what I am missing?
use:
=QUERY(A1:C8; "select A,sum(B),C where A is not null group by A,C"; 1)

How can I Use query to pull information from another google spreadsheet?

HI I have two google spreadsheets one spread sheet has multiple tabs with various information. The second spread sheet is a master data list of patients names and correlating information. As of now I have the mater data tab that i pull this information from. I would just like to simply move it to a separate sheet spreadsheet. This is the formula I use to pull data from the data tab (FC). =IFERROR(ARRAYFORMULA(JOIN(CHAR(10),QUERY(FC!$A$2:F,"Select D Where B='"&A21&"'"))))
How do I move tab FC to its own spreadsheet and get the same outcome on this sheet?
If you separate the master sheet, you will have to import data from the slave spreadsheets using IMPORTRANGE('ID of the source',sheet1!A2:F) for instance and then apply query on it. Give a link to a simplified mockup.
use:
=IFERROR(INDEX(TEXTJOIN(CHAR(10), 1, QUERY(IMPORTRANGE("sheet's_url", "FC!A2:F"),
"select Col4
where Col2='"&A21&"'"))))
example:
=IFERROR(INDEX(TEXTJOIN(CHAR(10), 1, QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1BhBUDx9LKKQIC2zQbDM2IOhVAV6ppygbts2vT-NmhAM/edit#gid=0", "data!A1:F"),
"select Col4
where Col1='"&A1&"'"))))

Combine data from multiple tables using indirect references in Google sheets

I am needing to combine all student attendance in one chart. I have tried Query, Vlookup, and Index Match - nothing seems to get the results I want. I need something to search first and last name and return all attendance from all sheets. I would like to use something like CHOOSE and INDIRECT due to the future size of this sheet.
Here is what I have tried:
=ArrayFormula(VLOOKUP(K2&L2,CHOOSE({1,2},{Indirect(E2) & INDIRECT(F2), Indirect(D2)},{1,2})))
=query(Arrayformula({INDIRECT(D2), Vlookup($K$2:$K$45 & $L$2:$L$45, {Indirect(E2) & INDIRECT(F2), Indirect(D2)}, false)}),"select Col1,Col2,Col3,Col10,Col17,Col24,Col31 where not Col1 is null",1
=ArrayFormula((VLOOKUP(K2,INDIRECT($D$3),{1,2,3,10,17,24,31})))
This is a very small example of what the final sheet will be. I included what I want the results to be on a separate tab.
https://docs.google.com/spreadsheets/d/1-XNePmTzVIc84ScasZxh1KlzTBxDyI_glxwg24uXGuI/edit#gid=868379110

How to add an extra column including tab name when merging multiple sheets in Google Sheets?

I'm trying to merge multiple tabs into one master sheet. This is working fine:
=QUERY({SheetOne!A16:B;SheetTwo!A16:B;SheetThree!A16:B;SheetFour!A16:B}, "SELECT * WHERE Col1 IS NOT NULL", 0)
And it gives me the table
Week,Users
12,123
13,234
14,345
12,123
13,234
14,345
12,123
13,234
14,345
However, I'd like another column that creates a reference to the sheet. So the result I'd like is:
SheetName, Week, Users
SheetOne,12,123
SheetOne,13,234
SheetOne,14,345
SheetTwo,12,123
SheetTwo,13,234
SheetTwo,14,345
SheetThree,12,123
SheetThree,13,234
SheetThree,14,345
Thanks. Bonus question: How to insert a custom string-value instead of SheetOne,SheetTwo [...]

Combining multiple spreadsheets in one using IMPORTRANGE

I would like to aggregate the data of multiple spreadsheets into one spreadsheet.
Spreadsheet 1 has a Row of Strings A2:A500
Spreadsheet 2 has a Row of Strings A2:A500
Spreadsheet 3 is supposed to have a Row of both (Spreadsheet1!A2:A500 AND Spreadsheet2!A2:A500).
Duplicates shall not be handled differently. I would like them to appear as often as they appear in the different sheets.
Is it possible to do this without writing a script or using jQuery, e.g. by using IMPORTRANGE?
What does not work: I have tried using IMPORTRANGE as follows:
ARRAY{IMPORTRANGE("key-of-spreadsheet1","list!A2:A500"), IMPORTRANGE("key-of-spreadsheet2", "list!A2:A500")}
This causes an error.
You should be able to use a vertical array in the Spreadsheet 3:
={IMPORTRANGE("Sheet1Key","SheetName!A2:A500");IMPORTRANGE("Sheet2Key","SheetName!A2:A500")}
Of course, it is also possible to combine several IMPORTRANGE() functions with the QUERY() function, which gives us a greater control over the results we import.
For example, we can use such a construction:
=QUERY(
{
IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-2", "'sheet-name-2'!A2:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-3", "'sheet-name-3'!A2:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-4", "'sheet-name-4'!A2:Z100")
},
"SELECT * WHERE Col1 IS NOT NULL ORDER BY Col3 ASC"
)
###Explanation:
The above query removes blank lines from imported ranges:
SELECT * WHERE Col1 IS NOT NULL
and sorts ascending all data collected together in relation to the third column:
ORDER BY Col3 ASC
For descending, just use DESC in place of ASC.
Of course, we can also arrange any other criteria, or omit them displaying everything without modification:
"SELECT * "
###Note:
In order to use the above constructed query, we first need to call a single IMPORTRANGE() method for each of the spreadsheets we want to refer:
=IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100")
We have to do this even if we refer to the same spreadsheet in which we write this formula, but for every spreadsheet it is enough to do it once.
This is to be able to connect these sheets and allow access to the sheets (to which we have the access rights anyway):
                                                    
After giving permission for all spreadsheets, we can use the above query.
I am also applying above given formula for getting data from multiple spreadsheet which is getting an error something is like IN ARRAY_LITERAL An array literal was missing values for one or more rows.
Easy fix: Apply the filter to the entire column / sheet instead of just the current selection. This will automatically update all of the filters to include new additions.

Resources