Import multiple Sheets into one with Criteria - google-sheets

I am trying to import several ranges from 8 different spreadsheets in to one master list.
This is my first Sheet.
This is my second Sheet.
This is my master list Sheet.
For now, I am testing it on just 2 spreadsheets. Will add the remaining once I figure this out.
So on my master list sheet, A4, I have this code
=query(
{
importrange("https://docs.google.com/spreadsheets/d/1scqPKhWpbZeOK_iYR7EaypNxMhh__V_O2FLUjbjrNFc/edit#gid=0","Scholarship Applicants Database!A4:W");
importrange("https://docs.google.com/spreadsheets/d/1PkBWxUG_0BG4gNhXFGHInSdVI5nMo4FReRpCQIVVs3w/edit#gid=664164578","Scholarship Applicants Database!A4:W")
},"Select * where Col1 <> ''")
Which works well. Then on Column X, these code does not work.
=query(
{
importrange("https://docs.google.com/spreadsheets/d/1scqPKhWpbZeOK_iYR7EaypNxMhh__V_O2FLUjbjrNFc/edit#gid=0","CDP Scoring Sheet (Initial)!G4:J");
importrange("https://docs.google.com/spreadsheets/d/1PkBWxUG_0BG4gNhXFGHInSdVI5nMo4FReRpCQIVVs3w/edit#gid=664164578","CDP Scoring Sheet (Initial)!G4:J")
},"select * where A = '"&$A4&"'")
What I am trying to do here is, import the ranges from Sheet1 and 2, from this sheet (CDP Scoring Sheet (Initial)), Column G4 to J, with the condition that Column A of Sheet 1 and 2 matches Column A of my Master list. Error I am receiving is "Unable to parse query string for function QUERY parameter 2: NO_COLUMN: A", I then change the "A" on the "where" part to "Col1", I get the error "Query complete with an empty output" and the result of "#N/A".
I also thought of changing my importrange from "G4:J" to A4:J" but I know it's not right cause it will then pull out the data from columns A to F which I no longer need.
Help please.

try:
=QUERY(
{
importrange("1scqPKhWpbZeOK_iYR7EaypNxMhh__V_O2FLUjbjrNFc", "CDP Scoring Sheet (Initial)!A4:J");
importrange("1PkBWxUG_0BG4gNhXFGHInSdVI5nMo4FReRpCQIVVs3w", "CDP Scoring Sheet (Initial)!A4:J")
},
"select Col7,Col8,Col9,Col10
where Col1 = '"&$A4&"'")

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

Importrange from multiple google sheets, issue when any one sheet has no data to import

I am importing data from two different Google sheets and merging them in another sheet. The formula which I used is as below .
=QUERY({
IFERROR(QUERY(
{ IMPORTRANGE("" , "Sheet1!$A$1:$b") },
"SELECT Col1,Col2 WHERE Col2='Total'",
0
)) ;
IFERROR(QUERY(
{ IMPORTRANGE("" , "Sheet1!$a$1:$b") },
"SELECT Col1,Col2 WHERE Col2='Yes'",
0
))
})
In above formula, importrange is giving the result when both sheets have data to import, but if any one sheet has no data to import the data from another sheet is not getting imported. I had figured a solution at below link where we can handle this issue by using dummy column reference, this approach is fine when we have few sheets to import with few columns but when we are importing from many sheets and many column to import the dummy column reference gets too long. Is there any other way to solve this issue.
The easiest way to do this is to use an IFERROR(SEQUENCE(1,n)/0) as your output for when a query of an importrange fails instead of needing to list a bunch of blanks.
The solution for your simple example looks like this where n = 2:
=ARRAYFORMULA(QUERY({IFERROR(QUERY({IMPORTRANGE("1hea986JF3plR_tn7plNRgjWhiGqxOlR8s8yE-Ri6FfU" , "Sheet1!$A$1:$b")}, "SELECT Col1,Col2 WHERE Col2='Total'",0),IFERROR(SEQUENCE(1,2)/0));IFERROR(QUERY({IMPORTRANGE("1IbPpoLLfa-ukoz2WInlgNGSNMNBxBwSx4in52fZCEyE" , "Sheet1!$a$1:$b")},"SELECT Col1,Col2 WHERE Col2='Yes'",0),IFERROR(SEQUENCE(1,2)/0))},"where Col1 is not null"))

Combine data from 2 forms to one sheet depending on the date in Google Sheets

I have 2 forms and I have their results on the same sheet. I used the following formula
=Query({importrange(...);importrange(...)}, "SELECT * where Col1 is not null")
I want to have all the results from 1 form and the results depending on the date from the other form on the same sheet.
I have tried the following formula for July
=Query({importrange(...);importrange(...)}, "WHERE month(Col1)=5")
but it shows ONLY the results with July in the date from both forms.
How can I combine the results?
EDIT 2
(following OP's concern)
...Looks like it works only when there are entries with July in the date in the second spreadsheet. I need all the entries in the first spreadsheet to be visualized at any time
We can easily fix that by wrapping the whole formula with the IFERROR function
=IFERROR({QUERY(IMPORTRANGE("xxxxxx","form1!A1:E"), "where Col1 is not null");
QUERY(IMPORTRANGE("xxxxxx","form2!A1:E"), "where Col1 is not null and month(todate(Col1))=6",0)},
QUERY(IMPORTRANGE("xxxxxx","form1!A1:E"), "where Col1 is not null"))
Just make sure that Col1 (the Timestamp) in your results sheet is formatted as Date time
This final formula says:
Import data from the 1st sheet and under it append data from the 2nd sheet based on a certain month.
If that month is missing (which results to an error), import data from just the 1st sheet.
EDIT
(following OP's clarification)
...but my results are not on the same spreadsheets. I'd like to keep them on different spreadsheets.
Since there are different spreadsheets involved you must use the IMPORTRANGE function (as you very correctly already do).
Then the formula would be:
={QUERY(IMPORTRANGE("xxxxxx","form1!A1:E"), "where Col1 is not null");
QUERY(IMPORTRANGE("xxxxxx","form2!A1:E"), "where Col1 is not null and month(todate(Col1))=6",0)}
(As before please adjust ranges to your needs. Just make sure you keep the same number of columns)
NOTES:
1. Though July is the 7th month, we use month(todate(Col1))=6. That is because in "query language" January is month 0 and not 1.
2. In our second part we use as headers 0. This way we get to avoid returning them for the second query.
3. Since the imports come from forms we keep open ranges so when new answers are submitted, then get imported as well.
If all your sheets are in the same spreadsheet, you do not need IMPORTRANGE.
Using INDEX -which is much "lighter"- your formula would be:
={QUERY({form1!A2:O29}, "where Col1 is not null");
QUERY({form2!A2:O29}, "WHERE month(Col1)=6")}
Now your form2 results will be placed under the ones from form1
Having an additional query, you can have them both ordered by the timestamp in column 1
=QUERY({QUERY({form1!A2:O29}, "where Col1 is not null");
QUERY({form2!A2:O29}, "WHERE month(Col1)=7")},"order by Col1")
(Please adjust all sheet names and ranges to your needs)

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)))

Resources