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&"'"))
Related
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
I have a small table with usernames and dates in a Google Drive spreadsheet as part of some manual logging.
e.g.:
| User1 | 01/09/2019 |
| User1 | 09/09/2019 |
| User2 | 13/09/2019 |
| User1 | 05/10/2019 |
(dates are formatted DD/MM/YYYY)
I want to create an overview of when each username was first logged. For this I created a second table with below function for the first column:
=UNIQUE(A2:A7)
For the second column, I wrote below function:
=QUERY(A2:B7, "SELECT MIN(B) WHERE A='"&C2&"'", 1)
The output I'm expecting to see is this:
| User1 | 01/09/2019 |
| User2 | 13/09/2019 |
But for some reason, the output I receive is this:
| User1 | min 01/09/2019 |
| User2 | 13/09/2019 |
What can I do to avoid the 'min' being added in the output? I don't see why this is being added in the first place.
You can do this in a single step with this formula:
=query(A:B,"select A, min(B) where A is not null group by A",1)
Also, I suspect your current date formatting is MM/dd/YYYY, and that's why "13/09/2019" isn't recognised as a date and creates weird behaviours.
Try to change the format (at least temporarily), using full months names, so you'll know for sure. If that's the case, just fix your dates and the formula above should do just fine:
Why does the min function apparently add the name of the function to the output?
A: because of that last 1 in your query formula.
instead, use this formula:
=QUERY(A1:B,
"select A,min(B)
where A is not null
group by A
label min(B)''", 0)
By putting ,1) after the query, you're telling it that the data (starting in row 2) has a header. So it uses whatever it finds in row 2 (1/9/2019) and adds it to the default header (min). If you would like your original formula to work as expected, change
=QUERY(A2:B7, "SELECT MIN(B) WHERE A='"&C2&"'", 1)
to
=QUERY(A2:B7, "SELECT MIN(B) WHERE A='"&C2&"' label min(B) ''")
I have a spreadsheet from a Google Consumer Survey. The survey captured demographics as well as the responses to a question. Acceptable responses could have chosen zero or more 'answers'. The response for each answer is in a unique column. For example,
user id | gender | age | income | answer 1 | answer 2 | answer 3 |
0001 | Female | 20-30 | 50-75 | [empty] | Right | Never |
0002 | Male | 20-30 | 30-50 | Up | Left | [empty] |
I would like to know how to correlate a column of demographic info with each of the possible answers. For example, I want to be able to answer questions like, Were males more likely than females to choose X for answer 1? and Which age group was more likely to choose Y for answer 2?
I prefer an answer using Google Sheets functions, but I am open to learning other ways to understand the data. Thank you for any help!
Good way is to use query function. Let's first assume, your data is stored in range A:G:
A | B | C | D | E | F | G |
user id | gender | age | income | answer 1 | answer 2 | answer 3 |
0001 | Female |20-30| 50-75 | [empty] | Right | Never |
0002 | Male |20-30| 30-50 | Up | Left | [empty] |
you may write simple query functions.
For example, to count all answer 1, group them by gender and age, pivot by answer 1:
=query(A:G,"select B, C, count(D) where not A is null group by B, C pivot E")
where not A is null -- prevents empty data to be used in query
count(D) -- can count any column, that wasn't already used by query
group by B, C -- must contain all selected items, except aggregates (count, sum, ets.)
pivot E -- will make all answers to show in separate columns.
The result will look like this:
Left Never Right Up
Female 20-30 1 1 1
Female 30-40 1
Male 20-30 1 1 1
Male 30-40 1
Please, look at complete Query Language Reference to learn more.
Have you tried using the Pivot Table function of Google Sheets?
Download the data in excel format after the survey is complete and open with Google Sheets
Select the tab with the resulting data from the Google Consumer Survey after it is run.
From the menu, select Data -> Pivot Table. This opens a new tab in your spreadsheet.
For the Values area of the pivot table, select User ID and from the "Summerize by" dropdown, select COUNTUNIQUE
For the columns and rows, select whichever dimensions you are interested in. For instance, in your example, you would pick
"Gender" and "Answer 1" as a row and column.
"Age" and "Answer 2" as a row and column.
This should answer these kinds of questions easily.
Hope this helps!
What I think I needed was the COUNTIFS function (in Google Sheets). Notice the plural use, which is different than countif (singular).
COUNTIFS allowed me to specify multiple criteria to make a score for each demographic segment. For example, I could count all the Males that responded Up in the answer 1 column.
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)
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' ")