Google sheets query different sheets from named range in dropdown - google-sheets

I have 2 sheets (sheet1 and sheet2) and have created named ranges for each of them named sheet1 and sheet2.
To query sheet1 i use the following formula:
=QUERY(sheet1, "select A,B,C")
When i want to query sheet2 i have to edit my query formula. I dont want to have to do that, instead i want to select the sheet to query from a dropdown.
In cell B2 i have created a dropdown using data validation which populates my dropdown with Sheet1 and Sheet2.
Ive then modified my query to:
=QUERY(B2, "select A,B,C")
But i get the following error:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: A
Is there a way to query each sheet by using a dropdown?

try like this:
=QUERY(INDIRECT(B2), "select A,B,C")

Related

Column LOOKUP Dynamic Query (Google Sheets)

Trying 'query' for the first time in google sheets. Need some assistance. Thanks in advance.
I have a google sheet with two tabs "sheet 1" and "sheet 2"
Sheet 1 Structure:
Sheet 2 Structure:
I am trying to create a dynamic query, where if Entity = Person "x" and Value = A or B or C, the Des number (from sheet2) is populated in Sheet 1 in yellow cells
So far I have tried these queries and for some reason it throws a "#N/A" error
QUERY({Sheet2!$A$1:$AC$10}, "SELECT Col1,Col"&MATCH(B1,Sheet2!$A$1:$AC$1,0))
LOOKUP($B$1,QUERY({Sheet2!$A$1:$AC$10}, "SELECT Col1, Col"&MATCH("L",Sheet2!$A$1:$AC$1,0)))
Can someone point me in right direction with this query?
It's bit more complex as you have first to unpivot Sheet2, then apply query, finally join the results in one cell.
=iferror(textjoin(char(10),,query(arrayformula(split(flatten(Sheet2!$A$2:$A$4&"|"&Sheet2!$B$1:$F$1&"|"&Sheet2!$B$2:$F$4),"|")),"select Col2 where Col1='"&$A2&"' and Col3='"&B$1&"' ")))
adjust Sheet2!$A$2:$A$4&"|"&Sheet2!$B$1:$F$1&"|"&Sheet2!$B$2:$F$4as necessary.
Explanation
Sheet2 is like
To unpivot Sheet2, try
=arrayformula(split(flatten(Sheet2!$A$2:$A$4&"|"&Sheet2!$B$1:$F$1&"|"&Sheet2!$B$2:$F$4),"|"))
then apply your query
query(_______________,"select Col2 where Col1='"&$A2&"' and Col3='"&B$1&"' ")
and finally join the results

New Google sheet combining columns from multiple sheets with join based on common field

I've 3 or more Google sheets. Each sheet covers different aspects of employee info. These sheets would get new entries added every now and then. All the sheets have ID column.
The new sheet has UNION of all fields from different sheets joined by a common field present in every sheet, e.g. email id.
For example:
Source 1:
Source 2:
Expected new sheet with the integrated data joined by email id is:
Ideally, the integrated sheet should not have the repetition of join key, i.e. Email.
I want this integrated sheet to be automatically updated with new rows as and when new data comes in all the sheets. Ideally, this should happen when data in all the source sheets are complete for a given ID.
What is the best way to achieve this?
use arrays {} like:
=UNIQUE(QUERY({Sheet1!A2:B; Sheet2!A2:B; Sheet3!A2:B};
"where Col1 is not null"))
update 1:
=UNIQUE(QUERY({
IMPORTRANGE("url_of_spreadsheet_here"; "Sheet1!A2:B");
IMPORTRANGE("url_of_spreadsheet_here"; "Sheet2!A2:B");
IMPORTRANGE("url_of_spreadsheet_here"; "Sheet3!A2:B")};
"where Col1 is not null"))
side note: each importrange formula needs to be run as standalone to connect your sheets by allowing access - only then you can use above formula
update 2:
if columns are mixed you can "correct" them like:
=UNIQUE(QUERY({
QUERY(IMPORTRANGE("url_of_spreadsheet_here"; "Sheet1!A2:C"); "select Col1,Col2,Col3");
QUERY(IMPORTRANGE("url_of_spreadsheet_here"; "Sheet2!A2:C"); "select Col3,Col2,Col1");
QUERY(IMPORTRANGE("url_of_spreadsheet_here"; "Sheet3!A2:C"); "select Col2,Col3,Col1")};
"where Col1 is not null"))

use Google Sheets QUERY to sum column where = x on a different sheet

I have a spreadsheet with 2 sheets in it,
I want to summarize the daily results by date.
I'm trying to use the query sum function to summarize everything since I wasn't able to do it with arrayformula.
but I'm not able to do it with a query as well.
I don't want to just copy-paste the sum function from each row to the next I want to just type the date I need in column A and get all the results in the different columns.
https://docs.google.com/spreadsheets/d/1ZsKXw32ycO_5KGD2I-Ug_GmqSIB_Z-D3Z1jlGd6fpTE/edit?usp=sharing
link to sheets.
getting the data from the database sheet.
I want to display the data-oriented by date and sumed.
for just 1 row you can simply do this and then drag down:
=ARRAYFORMULA(QUERY({TO_TEXT(DataBase!A:A), DataBase!B:E},
"select sum(Col5)
where Col1 = '"&TO_TEXT(A2)&"'
label sum(Col5)''", 0))
if array is needed then use:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, QUERY(DataBase!A:E,
"select A,sum(E)
where A is not null
group by A
label sum(E)''", 0), 2, 0)))

use Google Sheets QUERY to sum column weeknum = weeknum on a different sheet

I have a spreadsheet with 2 sheets in it, I want to summarize the weekly results by date. I'm trying to use the query sum function to summarize everything since I wasn't able to do it with arrayformula.
but I'm not able to do it with a query as well. I don't want to just copy-paste the sum function from each row to the next I want to just type the date I need in column A and get all the results in the different columns.
https://docs.google.com/spreadsheets/d/1ZsKXw32ycO_5KGD2I-Ug_GmqSIB_Z-D3Z1jlGd6fpTE/edit?usp=sharing
link to sheets.
getting the data from the database sheet. I want to display the data-oriented by date and summed.
=ArrayFormula(IFERROR(FILTER(QUERY(DataBase!A2:E,"select A,sum(E)
where A is not null
group by A
label sum(E)''"), WEEKNUM(DataBase!A2:A)=WEEKNUM(A2:A))
))
I tried this formula and it dosent work..
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A,
QUERY(FILTER(DataBase!A2:E,WEEKNUM(DataBase!A2:A)=WEEKNUM(A2)),
"select Col1,sum(Col5)
where Col1 is not null
group by Col1
label sum(Col5)''"), 2, 0)))

Extract rows from one google sheet to another based on criteria in column

I have a google sheet called "Senate." In Column E, some of the rows have "ID" in that column. I would like to copy the rows that contain "ID" in Column E and paste them into another sheet called "Targets." It is important the rows are not taken from the original sheet "Senate"
Assuming that with 'sheet' you do mean sheet (tab) and NOT a spreadsheet (workbook), in sheet Targets, A1 try:
=query(Senate!A:Z, "where E = 'ID' ",1)
Change range to suit.

Resources