I have two sheets in Google docs. The second one looks like this (simplified):
Reference | Comment | Author
-------------------------------
item1 | baz | John
item2 | bar | Mike
item1 | foo | Will
I can pull out a single entry using IMPORTRANGE like this:
=IMPORTRANGE("sheetid", "Sheet2!A3")
This would yield item1 in my example above. So far so good. What I would like to do is to use this sheet as a connection sheet with data for Sheet1. So perhaps using QUERY, I would like to do something like this (pseudo code obviously) from Sheet1:
=QUERY('Sheet2 data from IMPORTRANGE()', "select B, C where A = 'item1'")
to get all Comment and Author from all rows where the reference column equals item1.
Yes, but you will need to import more than single cell if to return an array of selected cells and also grant access permission. The syntax requires number rather than letter references, eg:
=query(IMPORTRANGE("key","Sheet2!A1:C4"),"Select Col2, Col3 where Col1= 'item1' ")
Related
I'm struggling to find a solution on my own and I couldn't find a relevant answer for my specific case (or a similar one) so here I am.
Before anything else I want to say thanks in advance for any help.
Here's my problem:
I have a Google Sheet with a table as follows:
email_address1#domain.com | group_address1#domain.com | group_address2#domain.com | group_address2#domain.com
email_address2#domain.com | group_address2#domain.com | group_address3#domain.com | group_address4#domain.com
...
So, basically it's a list of users in the first column and the groups that each user is a part of in the next columns. Each user is in more than one group.
Now I need to check which users are in each group (instead of checking in which groups each user is). I can easily flatten the range of groups and get the list of unique groups, but now I'm struggling to find a way to query the original table in order to get something like this:
group_address1#domain.com | email_address1#domain.com | email_address2#domain.com | emai3_address1#domain.com
group_address2#domain.com | email_address2#domain.com | email_address5#domain.com | emai3_address6#domain.com
Again, thanks for your help.
try:
=ARRAYFORMULA(SPLIT(FLATTEN(QUERY(QUERY(SPLIT(FLATTEN(A1:A9&"×"&B1:D9), "×"),
"select max(Col1) where Col2 is not null group by Col1 pivot Col2"),,9^9)), " "))
Finally I tried a different approach:
I joined all the group names in a helper column (Column U) and then used the following formula:
=TRANSPOSE(QUERY('Domain 2'!$E$90:$U$167,"select E where U contains '"&L67&"'"))
I created a pivot table in googlesheets, and it returns results that look like:
first | second | CountOf3
--------------------------
thing | value | 23
| newVal | 3
| cool | 34
that | value | 234
otherThing | cool | 4
| newVal | 345
And I want to filter out results with just one resulting row for the item in the first column.
So in this example, that would be the row: that | value | 234.
I would like the filter to remove that row, and leave the remaining rows. This is a pivot table in a 2nd sheet that updates when Sheet1 changes.
I have been trying all day, and have not been able to come up with a solution. I was hoping there would be some sort of filter, or spreadsheet formula to do this. I've tried multiple combinations of filters, but nothing seems to work - I'm starting to wonder if this is even possible.
It isn't pretty, but a brute force way is to have a check column beside your pivot table, with this formula on the first data row, ie beside "thing | value | 23".
It flags each row where the subsequent cell in column D is not blank. Then use a query (or filter) to list only the output rows you want. Note that you would hide the columns or rows with the actual (unfiltered) pivot output.
This is the simplest version, to see the logic:
=AND(LEN(D3),LEN(D4))
which results in a TRUE value for pivot chart rows that only have one value.
A more elegant version is an arrayformula, adds the header lable, and uses "Skip" as the flag for which rows to filter out.
={"Better Check";ARRAYFORMULA(IF(LEN(D3:D998)*LEN(D4:D999)*LEN(E3:E998),"Skip",))}
Note that this formula allows for a pivot table result effectively to the bottom of the sheet, but it does have a finite range, due to the constraint of checking two rows at once. It could be enhanced by using a COUNTA on the third data column to measure the exact length of the pivot table results and control the range dynamically, Like this:
={"Better Check";
ARRAYFORMULA( IF( LEN(INDIRECT("D3:D" & (COUNTA(F$3:F)+ROW(F$2)))) *
LEN(INDIRECT("D4:D" & (COUNTA(F$3:F)+1+ROW(F$2)))),
"Skip",))}
Let us know if this helps at all.
I have a Google Sheet linked to a Google form to record user input in a way that is easily manipulatable. For my example purposes, let's say this is simply a form to get user comments.
In this example, I have the sheet titled "Data" that retrieves the form submissions. This has the following headers:
|-----------|--------|-----------|
| Timestamp | User | Comment |
|-----------|--------|-----------|
New form submissions are actively being added to this sheet.
I am pulling this data to another sheet, titled "Report," via a QUERY FUNCTION. I would like to sort these comments under their select user. Here is the layout of my Report sheet:
|----------|---------|
| User 1 | |
|----------|---------|
| | QUERY |
|----------|---------|
| User 2 | |
|----------|---------|
| | QUERY |
|----------|---------|
| User 3 | |
|----------|---------|
| | QUERY |
|----------|---------|
The cells with "QUERY" will have something along these lines:
=QUERY(Data!A1:C,"Select * Where B = 'User 1'", 1)
What I want to do is have new rows dynamically added to the associated query as each user sends in multiple submissions; that way there is enough room for the Query data and I won't get an error.
How can this be done?
If you are open to slighly change the report structure in order to keep things simple use the ORDER BY clause of Google Query Language in a single formula using the QUERY function
The formula will be something like this:
=QUERY({Data!B1:B,Data!A1:C},"Select * Order By Col1", 1)
Then you could use conditional formatting to set the font and background color to be the same if the cell value is the same of the above cell.
If you really need to have a stepped report, then add a set of rows having only the User name. Example:
=ArrayFormula(QUERY(
{Data!B:B,Data!A:C;UNIQUE({Data!B2:B,IF(LEN(Data!B2:B),{"","",""})})},
"Select * Where Col1 is not null Order By Col1, Col2", 1
))
Resources
Google Query Language
Using arrays in Google Sheets
hi I have a spreadsheet file contains a names of books at column A and the type of the books in column B.
and at the same file I have another sheets each one contains a specific type of books ex: sheet 2 contains the history booksK sheet 3 contains science ..etc
my Question is :
how to import the books from sheet1 (which contains all books)
to the other sheets dependeing on the type name
(take from sheet 1 to sheet 2 all books its type is history)
I tried this formula: =QUERY(IMPORTRANGE("sheet key","Sheet1!A:C"),(select* where COLUMN(B) contains"history")) but it doesn't work ......
Either
=filter(books!A:B, books!B:B = "novel")
or
=query(books!A1:B, "where B = 'novel'")
will work.
So your data looks like this, sheet is named "books" and other sheets are named by book types:
__| A | B |
1 | Who Moved My Cheese? | Self-help |
2 | the hunger games | novel |
3 | the winner stands alone | novel |
You can use filter() function instead of query(). Here is formula to your 'novel' sheet:
=filter(books!A:A, books!B:B = "novel")
"books!" is reference to your sheet that contains data and "novel" is the type to search for. Now you can use this formula for every other sheet by changing only search term "novel" to whatever is desired.
=iferror(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/[YOUR_KEY_FROM_URL]/edit","Title of Sheet You are Using!A2:I42"),"select * WHERE Col5 CONTAINS 'Towel'",1),"no values yet!")
Lets break it down a bit
IFERROR allows you to display a user friendly message if this fail because no data is returned
QUERY allows you to specify the search criteria. You can omit this if you simply want to import the range of cell regardless.
IMPORTRANGE Use the url provided, then fetch this sheet, looking at these ranges (top left, to bottom right)
So I'm stuck with something. I have two spreadsheets, column A on each are similar but not identical, some values are on one spreadsheet but not the other.
Is it possible for me to pull data from spreadsheet 2, based on if column A has a matching value?
So spreadsheet 2 will have something like:
A B
item1 100
item2 200
item3 300
and spreadsheet 1 will have something like:
A B
item1 NULL
item2 NULL
item4 NULL
I want to populate the B columns on spreadsheet 1 based on whether they are on spreadsheet 2 (in this instance, it would populate items 1 and 2)
I've tried VLOOKUP and If statements but don't seem to be getting anywhere.
The VLOOKUP function will do this for you, providing that you set the optional is_sorted parameter to FALSE, so that closest matches will not be returned.
Here's an example. First, our source sheet, Sheet1.
On Sheet2, we use VLOOKUP to pull info from Sheet1, using this formula (from B1, in this case):
=vlookup(A1,Sheet1!$A$1:$B,2,false)
^ -------------- ^ ^
| | | +-- is_sorted
| | +------- return value from col 2
| +------------------- Range for search
+------------------------- search_key
Ok, but that #N/A for item4 is not pretty. We can suppress it by wrapping the VLOOKUP in IFERROR. When the optional second argument of IFERROR is omitted, it will return a blank cell if the first argument evaluates to an error:
=IFERROR(vlookup(A1,Sheet1!$A$1:$B,2,false))
In your example, the data is coming from a separate spreadsheet, not just a different sheet within the current spreadsheet. No problem - VLOOKUP can be combined with IMPORTRANGE as its data source.
=IFERROR(vlookup(A1,IMPORTRANGE("<sheet-id>","Sheet1!A1:B"),2,false))
Due to recent changes in Google Sheets, the formula from AdamL and Mogsdad only seems to work when you connect the 2 sheets together.
Remove parts from the formula that don't belong to the importrange..
=IMPORTRANGE("<URL other sheet>";"Sheet1!A2:C")
You get a REF# error but when you hover over the error you can confirm a connection.
I confirmed it works for all cells so you can copy paste the complete formula.
=IFERROR(vlookup(B128;IMPORTRANGE("<URL other sheet>";"SHeet1!A2:C");3;false);)
Following the official documentation you need the complete URL from the other sheet..