Stacking multiple query output in one sheet - google-sheets

For my department I made a dynamic and flexible overview sheet for every teacher, showing his of hers tutored students.
In one overview sheet I have made several query's, that gather data form different sources (students and teachers in different years). The query's are in one column, because I want to generate a list per teacher.
But the output the query formula generate, can differ in length (= number of rows it takes = number of students), that's is why I have to allow for a fixed number of rows in the overview sheet. And that can lead to ugly blank rows in my list.
Is there a way to keep the flexibility (for every teacher has a different number of tutored students), but remove the blank rows?

If any sheet for every teacher has the same number of same columns, then your data is well-structured and you could make single query on them.
=query({Sheet1!A1:C;Sheet2!A2:C},"select * where Col1 <> ''")
Pay attention on some details:
query should take only one row with headers, use Sheet1!A1:C with headers and the others SheetName!A2:C
when query have source, that contains of multiple tables, use Col1, Col2, Col3... instead of column's letters A, B, C... It may be even more convenient. This rule also works, when data is imported from another file.

You can combine ranges using , for columns and ; for rows and by wrapping the ranges in {}. (You need to add the curlies after indicating you are concatenating ranges)
Assuming in Sheet1 you aggregate the data from Sheet2 and Sheet3you can use:
={QUERY(Sheet2!A2:B, "SELECT A, B WHERE A <> ''");
QUERY(Sheet3!A2:B, "SELECT A, B WHERE A <> ''")}
Where A is the student names (or whatever cannot be empty) and B something arbitrary like marks. Of course that query can be as complex as you want (probably best to prebuild it and reuse it via reference then).

Related

Is there a formula to resolve duplicates in one column by looking at a second column?

I have a google sheet with 2 columns, A (containing names) and B (containing dates).
there are quite a few duplicates in A which I need resolved by looking at B and selecting the row with the soonest date.
Ideally I need to extract the data to make a list on another sheet with no duplicates, being resolved by the above method. the issue is that there might be new rows added to the sheet, and I need the new rows checked against the existing data to confirm it has a sooner date compared to potential duplicates. how can I formulate this?
There is probably a better way, but I just use the query function to put the results in a different sheet so I don't mess with the source data.
=QUERY()
Here is some examples on how it is used: https://support.google.com/docs/answer/3093343
As for the query itself, something like this should work. A being the first column (Name), and B being the second column (Date).
SELECT A, MAX(B) GROUP BY A

Google Sheets Count Unique Dates based upon a criteria in different columns

I am trying to find a formula that will give me the count of unique dates a persons' name appears in one of two different columns and/or both columns.
I have a set of data where a person's name may show up in a "driver" column or a "helper" column, multiple times over the course of one day. Throughout the day some drivers might also be helpers and some days a driver may come in for duty but only as a helper. Basically all drivers can be helpers, but not all helpers can be drivers.
I've attached a link to a sample sheet for more clarity.
https://docs.google.com/spreadsheets/d/1GqNa1hrViX4B6mkL3wWcqEsy87gmdw77DhkhIaswLyI/edit?usp=sharing
I've created a REPORTS tab with a SORT(UNIQUE(FLATTEN)) Formula to give me a list of the names that appear in the DATA Tab.
I'm looking for a way to count the unique dates a name from the name (Column A of the REPORTS Tab) appears in either of the two columns (Column B and/or C of the DATA Tab) to determine the total number of days worked so I can calculate the total number of days off over the range queried.
I've tried several iterations of countif, countunique, and countuniqueifs but cannot seem to find a way to return the correct values.
Any advice on how to make this work would be appreciated.
I think if you put this formula in cell b7 you'll be set. You can drag it down.
=Counta(Unique(filter(DATA!A:A,(DATA!C:C=A7)+(DATA!B:B=A7))))
Here's a working version of your file.
For anyone interested, Google Sheets' Filter function differs slightly from Excel's Filter function because Sheets attempts to make it easier for users to apply multiple conditions by simply separating each parameter with a comma. Example: =filter(A:A,A:A<>"",B:B<>"bad result") will provide different results between the Sheets and Excel.
Excel Filter requires users to specify multiple conditions within parenthesis and denote each criterion be flagged with an OR condition with a + else an AND condition with a multiplication sign *. While this can appear daunting and bizarre to multiply arrays that have text in it, it allows for more flexibility.
To Google's credit, if one follows the required Excel Syntax (as I did in this answer) then the functions will behave the same.
delete what you got and use:
=QUERY(QUERY(UNIQUE({DATA!A:B; DATA!A:A, DATA!C:C}),
"select Col2,count(Col1),"&D2&"-count(Col2)
where Col2 is not null
group by Col2"),
"offset 1", 0)

A need to tie up cell to it's neighbor

I use spreadsheets to manage Google Ads campaigns. In first column I import campaign names using Query function:
=QUERY('data-campaigns-all'!A:H,"select B, count(A) where A > date '"&TEXT(DATEVALUE($S$1-14),"yyyy-mm-dd")&"' group by B order by B LABEL count(A) ''")
So I have a list of active campaigns for the day. I import other values (such as number of clicks, conversion values and so) based on campaign name, using sumifs or other formulas.
But I manually add a column with a budget for every single campaign. And it's just plain number. And when a new campaign pops up in the list, it adds a new row and whole dataset switch. All other metrics are tied up with campaign name, by some kind of formula (sumifs, vlookup and so) but budget (plain number) always stays at its place while other data shift.
So I want to tie up the first column (with campaign names) with budgets (which are added manually and are not in source data). The only solution that came up in my mind was to add a static sheet with campaign names and corresponding budget values and then add it to my final sheet using VLOOKUP, but I hope there's an easier solution.

If a value in a cell has a duplicate within same column, delete both cells

What I want to happen is if a value on Sheet1 exists in Sheet2, I want them both to delete. Essentially, i want a list of cells that do not exist in both sheets. I have queried an array that combines two columns on different sheets. I am just stumped on how to delete both cells (automatically) if they exist twice.
For reference, the first sheet has a list of incoming product's serial numbers, The second sheets has a list of those same products that are now going out. I want an active list of what i have in-house.
Sheet one
Sheet two
Sheet three combining the both
This formula will work
=query({incoming!B:B, outgoing!C:C}, "select Col1 where Col1 <> Col2",0)
Assume we have an 'incoming' sheet for incoming products, and 'outgoing' sheet for outgoing products.
Assume we want to list on 'stock', all the stock that has come in, but has not gone out - in effect a list of the stock on hand.
The formula is entered anywhere in the "stock" sheet.
Layout of the "incoming" sheet
Layout of the "outgoing" sheet
Results in the "Stock" sheet
The query uses curly brackets to group together two arrays. This is described (albeit briefly, in Using arrays in Google Sheets.
The stock codes on the "incoming" sheet will include all products, regardless of whether they are outgoing, or they are still on hand. So we compare the codes in this array to the "outgoing" codes and apply the criterion of "where Col1 <> Col2". That is, where the code is in 'incoming" but not in "outgoing".

Summing cells which have certain value next to them AND a certain value is in another column

https://docs.google.com/spreadsheets/d/1xdB1Dl58aGsCOj1Xu1RZRB52Fn4RwbXDHlhuUDHZ1DU/edit?usp=sharing
I maintain spreadsheets for a sawmill. There are different suppliers and wood from them is split into different categories. What I want to do in the summary sheet, is to sum certain values from the Deliveries sheet, so I get an overview of how much of a certain kind of wood we received from a supplier.
Let's do it for "Alice" and "pine". How much pine has Alice brought in this month? I have no problem looking for every "pine" entry and summing it up, as demonstrated in the example, but I want only these pine entries, which are under "Alice" supplier entry. I assume I have to use sumifs(), but what complicates matters is that the "Alice" keyword often isn't straight to the left, because each separate truck is denoted by one supplier entry. Might sound complicated, but the spreadsheet should explain it very well.
I have no idea if there's something way simpler, but unless there is, I want a cell in the "Summary" sheet show me a sum of only those entries in "Deliveries" which have "pine" in the cell to the left AND have "Alice" in the cell two columns to the left or in the first non-empty cell above that in that column.
First obvious suggestion might be to just fill every row with a supplier name, but our actual files and the amount of types of wood are gigantic, it's a no-go. Also other sheets are based on delivery numbers, which are tied to suppliers having a single entry per delivery.
Thanks!
Make sure that every row has a name (in col C) for every type and quantity that is filled in. Then you can try QUERY() for the totals per person:
=query(Deliveries!C1:E, "select C, sum(E) where C <>'' group by C pivot D")
and another QUERY() for the totals
=query(query(Deliveries!D1:E, "select sum(E) pivot D"), "offset 1", 0)

Resources