Combining multiple Google sheets into single Google spreadsheet - google-sheets

I have multiple google sheets (45 of them, all dynamic, its content will keep on changing) and I want to combine data of all of them into a single file. I was hoping to use some importrange or QUERY function so that moment one / any file is updated, the changes reflect automatically on the combined sheet.
Example book 1 :
https://docs.google.com/spreadsheets/d/1sOkV9BT8ptndE0xcN2MUi4tTZ5p-aZxuLY_u29Y6nBI/edit?usp=sharing
Example book 2 :
https://docs.google.com/spreadsheets/d/1jZml9oVI2Flma407AB4ndl_ZIsQ_5I8zhkzvbL_EO_g/edit?usp=sharing
Example combined book :
https://docs.google.com/spreadsheets/d/1LkiIY1aUmwaouR7f4KhaGs6MV365KY7DYUPMiTzxjvc/edit?usp=sharing

first you need to connect them by pasting each IMPORTRANGE formula in some cell to get #REF! error
then hover over that #REF! error with your cursor and a secret magic button will popup
click on it to allow access
then you can stack up all import ranges and wrap them in a query:
=QUERY(
{IMPORTRANGE("ID1-or-URL1", "Sheet1!A1:A");
IMPORTRANGE("ID2-or-URL2", "Sheet1!A1:A");
IMPORTRANGE("ID3-or-URL3", "Sheet1!A1:A");
IMPORTRANGE("ID4-or-URL4", "Sheet1!A1:A")},
"where Col1 is not null"), 0)
update:
={ IMPORTRANGE("1sOkV9BT8ptndE0xcN2MUi4tTZ5p-aZxuLY_u29Y6nBI", "Sheet1!A1:N2");
QUERY({IMPORTRANGE("1sOkV9BT8ptndE0xcN2MUi4tTZ5p-aZxuLY_u29Y6nBI", "Sheet1!A3:N" );
IMPORTRANGE("19SFnJab9xVW2SenK-8IuG2cQRT2exJeyqARjTdDE_R8", "Sheet1!A3:N" )},
"where Col1 is not null", 0)}

Related

Combining multiple IMPORTRANGE WITH QUERY

I'm trying to import data from multiple spreedsheet to one using query,
=QUERY({IMPORTRANGE("1wMGl6qkQuz5ux42u4w8YAIEGiB3SN2b4EcgVJI-RTx4","DELIVERY DETAIL!$A$3:$I");
IMPORTRANGE("1A2dgmXRWbCzc9_jH38WruOMALsXrq8RFx7BcDW9Z8EI","DELIVERY DETAIL!$A$3:$I") },
"SELECT Col1,Col8,Col9 ",0)
the problem for me i get the data from one spreedsheet and receive nothing from the 2nd one,(i tried both of the importrange seperately without the query and it's working good), and it's importing the data from the source but when both of the importrange work it bring just data from 1st spreedsheet
BTW the name of the tabs are the same as i made duplicate the same spreedsheet
you did not filter out empty rows. try:
=QUERY({
IMPORTRANGE("1wMGl6qkQuz5ux42u4w8YAIEGiB3SN2b4EcgVJI-RTx4","DELIVERY DETAIL!$A$3:$I");
IMPORTRANGE("1A2dgmXRWbCzc9_jH38WruOMALsXrq8RFx7BcDW9Z8EI","DELIVERY DETAIL!$A$3:$I")},
"select Col1,Col8,Col9
where Col1 is not null", 0)

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

How to fetch specific data for specific word/phrase into a single cell in Google sheets

I have data in columns A:F and unique entries in column H. I'm using the data in column H to filter it's data from the first two columns and return data in the 5th and 6th columns (E and F).
I have tried and got myself a working formula but it's incomplete to get me the data I need. The formula is:
=IFERROR(QUERY(INDEX(SORT(FILTER({E2:E, ROW(A2:A)}, (A2:A=H2)+(B2:B=H2)), 2, 0),,1),,100000))
*The query function is to allow more than 50000 characters in that happens.
Please check out my data in this google sheets file to better understand.
https://docs.google.com/spreadsheets/d/1hGy_bIAzKj8Qq0l2BGu2ya6mrYaD7pmixPQISzunHrI/edit?usp=sharing
delete E:F and use this in E2:
=ARRAYFORMULA(IF(A2:A="",,"<td class="""&
IF(C2:C>D2:D, {"win", "loss"},
IF(C2:C<D2:D, {"loss", "win"}, "draw"))&"""></td>"))
then use this and drag down:
=ARRAYFORMULA(QUERY(INDEX(QUERY(SORT({SPLIT(QUERY(
FLATTEN(IF($A$2:$B="",,$A$2:$B&"×"&$E$2:$F)),
"where Col1 is not null"), "×"), SEQUENCE(COUNTA($A$2:$B))}, 3, 0),
"where Col1 = '"&H2&"'"),,2),,9^9))

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)

Is there a way to link data by names in Google Sheets?

I am using Google Forms and Sheets to create a way of tracking services including time for some of our students. I have the forms linked to a Sheet and am able to pull the "Clock In" data and "Clock Out" data into a single sheet. My issue is: when I go to analyze using pivot tables it pulls the data from the cell of the next row (students do not necessarily clock in/out in the order they arrive). Is there a way I can link the data by name and then order by time?
Any help would be greatly appreciated!
Example Sheet
you can but not in one go because pivot tables are not so advanced. create a new sheet and paste this in A1 cell and then crate your pivot table from this sheet:
={QUERY({Combination!A1:E}, "where Col1 is not null order by Col3, toDate(Col1) , toDate(Col2)", 1),
QUERY({Combination!F1:I}, "where Col1 is not null order by Col3, toDate(Col1) desc, toDate(Col2) desc", 1)}

Resources