How join other sheet to main sheet like DB relation? - google-sheets

I have a sheet name 'test'
code | count
HHHD |
YTSS |
YDUS |
and i have a second sheet name 'abc'
code | count | name
HHHD | 1 | sts
YTSS | 2 | other_name
YDUS | 6 | other_name_2
How create array formula or which function use to make in test B2 cell when code from test will exist in abc.cell then get data abc.count and insert to test.count
How can i do this ?

Classic VLOOKUP case:
But, I'll use LOOKUP here
Test B2=
=ARRAYFORMULA(LOOKUP(A2:A7,'abc'!A2:B7))

The QUERY function offers a short, readable way to analyze data. This function uses the principles of Structured Query Language (SQL) to do searches.
Parts of a QUERY formula
A QUERY formula is formatted as =QUERY(data, query, [headers]).
Full Documentation : Here

Related

Dynamically add rows to expand QUERY

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

Sorting data on google sheets

Looking for a bit of help creating a small database for orders.
So currently I'm parsing orders I receive to a order list on google sheets.
I have a few columns like customer name, date, reference number, address, etc.
Trying to have 1 main order sheet with all parsed orders, then have orders sorted by month in separate sheets and removing duplicate order entries.
You can write the script in given documentation for removing duplicates:
https://developers.google.com/apps-script/articles/removing_duplicates?hl=zh-TW
And For sorting of order:
var ss = SpreadsheetApp.getActiveSpreadsheet();//create object for google spreadsheet.
var timeSheet= ss.getSheetByName("sheetName");//create object for particuler sheet
var timeSheetLastRow = timeSheet.getLastRow();
timeSheet.getRange("A3:BC"+timeSheetLastRow).sort(7);// 7 is column number
You can try those things merge code for your sheet.
Let's create a dummy data that matches your content in Google Sheet.
A | B | C | D
-------------------------------------------------------
customer name | date | reference number | address
ABC | 1-1-1990 | 00100 | Home Towm
EFG | 3-2-1991 | 00200 | Farm Towm
HIJ | 2-3-1990 | 00300 | Your Towm
ABC | 1-1-1990 | 00100 | Home Towm
Let's assume the data above is added manually, and there is another sheet in the same SpreadSheet where sorted & unique data will be added from above sheet.
Formula: Unique(Sort('Sheet Name'!A:D, sort_column, is_ascending))
Example: Unique(Sort('Sheet Name'!A:D, 2, True))

Why does the min function apparently add the name of the function to the output?

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

Google Sheets: How to eliminate duplicates in some columns and show only the most recent data in others?

I have a spreadsheet of books, with one row for every time a book was checked out (this is a small classroom library). Here are the columns:
BookTitle | Author | DateCheckedOut | CheckedOutBy | Status
=========================================================================
The BFG | Dahl, Roald | 6/1/2016 | Suzy | Out
The BFG | Dahl, Roald | 4/5/2016 | Johnny | Returned
The BFG | Dahl, Roald | 12/4/2015 | Wendy | Returned
Charlotte's Web | White, E.B. | | | Added
Wonder | Palacio, R.J. | 5/29/2016 | Joey | Returned
Wonder | Palacio, R.J. | 3/21/2016 | Mary | Returned
I want to query it to get only the row with the highest date value for each book and then display all columns of that row except CheckedOutBy.
I wanted to get a list of unique book title / author combinations and then join it with the original table the way I would in DB2, but it seems that joins like that are not possible in Google Sheets. I tried grouping and the max function, but when I get those things to work I either haven't been able to eliminate earlier dates or haven't been able to display columns that aren't being used in the aggregate function. My Google Sheets querying skills are not up to par :/
Is there a simple way to do this that I'm missing? I would appreciate any tips.
Here's a copy of that sample data from above in a Google Sheet.:
https://docs.google.com/spreadsheets/d/1J384S0fsc8tgxVMehPb_uyRNc5-6cQx-xKN-q8K8Gds/edit?usp=sharing
I created a new sheet and entered in cell A1
=ArrayFormula(iferror(vlookup(unique(Sheet1!A2:A), sort(Sheet1!A2:E, 3, 0), {1, 2, 3, 5}, 0)))
See if that works for you ?
BREAKDOWN:
The general idea behind the formula is to make use of the fact that VLOOKUP only returns the first match. We want that 'first match' to be the latest date per book.
So first we sort the table so that the latest dates are on top.
We 'lookup' the unique book titles in that sorted table and we return the columns {1, 2, 3, 5}.
Links:
sort() function
vlookup() function

Google Spreadsheet: avg datediff returns error

I'm trying to build a report in Google Spreadsheets using the query() function. I want to select the average date difference using the dateDiff() and avg() functions.
Here is my query:
select avg(dateDiff(A, B))
And here is the table I'm trying to select from:
+---------------------+---------------------+
| A | B |
+---------------------+---------------------+
| 01/08/2013 15:41:00 | 31/07/2013 13:35:00 |
+---------------------+---------------------+
| 31/07/2013 17:17:00 | 31/07/2013 09:57:00 |
+---------------------+---------------------+
| 06/08/2013 15:14:00 | 29/07/2013 13:50:00 |
+---------------------+---------------------+
And this is the error message I get:
error: Invalid query: Query parse error: Encountered " "(" "( "" at line 1, column 20. Was expecting: ")" ...
Here is an open copy of the spreadsheet I've been working on.
https://docs.google.com/spreadsheet/ccc?key=0AhEoOqMhLAGbdEE1ZkhqSjlDT0lYVnVhY3hjNmlWZ3c#gid=0
Is it even possible to do with using the query() function?
If I'm understanding correctly, you require a single average of all the date differences. In which case it would be best to use the AVERAGE spreadsheet function outside the QUERY function.
=AVERAGE(QUERY(A1:B3;"select datediff(A,B) label datediff(A,B) ''"))
It actually isn't really necessary to put the label datediff(A,B) '' as the AVERAGE function will ignore the text header populated by the QUERY, but I put it in for the sake of completeness.

Resources