Sorting data on google sheets - 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))

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

Count values in another sheet in Google Spreadsheet where sheet name is a cell value using ARRAYFORMULA

I have a Google Spreadsheet with multiple sheets. I cannot share a sample because this is G-Suite Enterprise and it is locked. If absolutely needed I can create a dummy one on my personal Gmail.
One of the sheets has a list of lookup values and sheet names. I am trying to come up with an ARRAYFORMULA that will count the # of times Lookup Value shows in column A of Lookup Sheet Name.
| Lookup Value | Lookup Sheet Name | Count |
|--------------|-------------------|-------|
| one | Primary | ... |
| two | Secondary | ... |
| three | Stuff | ... |
| ... | Primary | ... |
| ... | ... | ... |
I came up with this formula For C2 but it does not work. I don't exactly know why but it shows 1 for every lookup value or just one row with 1.
=ArrayFormula(IF(A2:A <> "", COUNTIF(INDIRECT(B2:B & "!A2:A"), A2:A), ))
I do not want to use Google Apps Script to solve this.
Here is one possible solution that combines the values of the different sheets in one by adding a second column with constant value (the name of the seet for example).
=ArrayFormula(
IF(A:A<>"",
COUNTIFS(
{
FILTER('sheet A'!A:A,NOT(ISBLANK('sheet A'!A:A)));
FILTER('sheet B'!A:A,NOT(ISBLANK('sheet B'!A:A)))
},"="&A:A,
{
FILTER(IF(ISBLANK('sheet A'!A:A),,"sheet A"),NOT(ISBLANK('sheet A'!A:A)));
FILTER(IF(ISBLANK('sheet B'!A:A),,"sheet B"),NOT(ISBLANK('sheet B'!A:A)))
},"="&B:B
),
)
)

How join other sheet to main sheet like DB relation?

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

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

Structuring a query between multiple tabs to join values by name

I'm trying to write a SQL query in Google Sheets to try and get data for "matching" results from two different tabs, but running into some trouble.
This is a sheet that's basically an automated scoring engine for instructors who take a two-part test (written and practical). After the results are entered, I'd like to use some SQL to take the results from the two tabs and collate them into a final score.
Link to the sheet in question.
There's a "Practical Scores" tab (which takes all the data from the associated Google Form), and a "Written Scores" tab. I'd like to get the name of the instructors who match in both those tabs, and give the associated score for them, but I'm mostly having trouble with writing the correct SQL.
Most of what I'm trying to do is working fine. I'm able to pull the final practical scores via the following SQL:
=query(PracticalScores!A2:E, "select A, count(E),SUM(E)/3 group by A")
I can also pull the written scores as follows:
=query('Written Scores'!B2:C,"select B,C")
But I want the intersection of the two as well, and that's where I'm running into problems.
=query(A8:E, "select A,C,D where A = E")
will simply return the rows where the names match up, and I want the instances where the names match up, regardless of whether the rows do.
That is, I want all the rows where the names match from tab 1 to tab 2 and not just the few rows that happen to line up perfectly.
If I'm not explaining this well, please let me know and I can provide additional information. Any assistance would be very greatly appreciated!
Since the query function does not support joins, this can't all be done in one query. Instead, the following device can be used:
=arrayformula(vlookup(name column, table, # of column to extract, False))
For example, suppose I have a table
+---+-------+---+
| | A | B |
+---+-------+---+
| 2 | Jim | 3 |
| 3 | Sarah | 4 |
| 4 | Bob | 5 |
+---+-------+---+
to which I want to add another column, taking it from
+---+-------+---+
| | E | F |
+---+-------+---+
| 2 | Sarah | 9 |
| 3 | Bob | 8 |
| 4 | Jim | 7 |
+---+-------+---+
The basic idea is to put in cell C2 the formula
=arrayformula(vlookup(A2:A, E2:F, 2, false))
which will look up every name from first table (column A) in the column E, and return the matching value in column F. Result:
+---+-------+---+---+
| | A | B | C |
+---+-------+---+---+
| 2 | Jim | 3 | 7 |
| 3 | Sarah | 4 | 9 |
| 4 | Bob | 5 | 8 |
+---+-------+---+---+
In practice, one should filter out empty lookup values to improve performance:
=arrayformula(vlookup(filter(A2:A, len(A2:A)), E2:F, 2, false))
If the second table contains some names not present in the first, they will not be returned by the above formula. In this case it is better to prepare a full list of names, for example with
=sort(unique({Sheet1!A2:A; Sheet2!A2:A}))
which collects the names from A columns of two sheets, eliminating duplicates and sorting. Then look up those using vlookup as above.

Resources