Query command in google spreadsheet - google-sheets

my question isn't exactly about programming but I need help with google spreadsheets.
So my problem is visible here: https://docs.google.com/spreadsheets/d/1OP_ottKUgSWOoU4hNSYz6X3dN67Z4KiALN0spWm9KoI/edit?usp=sharing
I am a teacher and I have a class of students that is being divided into three teams: yellow, red and green. Each member of a team has to perform the same task three times a week (namely run1, run2 and run3). Every week I calculate the average of the performance of each student (300s = best). What I would like to know is which team is the most efficient. In the < Average > sheet I want to retrieve only the average value of each student without doing manually copy-paste.
I thought I could use the query command but it fails to give me what I need.

Check out this copy of your spreadsheet and take a look at the sheet 'JP' where I entered in cell A3:
=query(Students!A3:AA, "select A, B, C, G, K, O, S, W, AA")
This formula imports only the columns with the averages.
Then in cell K3, I added a second query
=query(C2:I, "select C, sum(D), sum(E), sum(F), sum(G), sum(H), sum(I) where C <>'' group by C ", 1)
that sums the averages per group (color), per week.
See if that helps ?

Related

Google Sheets query function based on multiple rows and/or columns

Data Sheet
Please assist a newbie with a query about query where 1 = Total Gross or Employers Cost based on the department and pay period.
So from the Data Sheet to a query on another sheet, I would be able to select February and Data it would produce Column C, D, I & J
Thanks in advance
Use this formula
=QUERY(Sheet1!A:J, "Select A, C, D, I, J Where A = '"&$B$3&"' ", 1)
Demo

How to get IF Function in spreadsheet based on data in column C and D to count amount of size

I need if function to count amount of size from column in C and D automatically.
Could anybody help me?
I count it manually by sorting male and female first then I used formula =COUNTIF(C2:C6,"XXL") to get how many male with size XXL.
Below is the picture in spreadsheet, and the green color is the result I want.
Sample
Clear E:J and put it in E1
=QUERY(C:D,"select D,count(D) where D is not null group by D pivot C",1)
Or only clear G:G and J:J, put it to G2 first and then copy and apply to J2
=ARRAYFORMULA(IF(E2:E="",,COUNTIFS($D:$D,E2:E,$C:$C,E1)))
Simply use
=QUERY(A1:D, ”SELECT D, COUNT(D) GROUP BY D PIVOT C”,
1)

Google Sheets Combine a column with duplicates and update total sum in another colum

This might be something fairly simple but struggling to find a way to do it.
In Column B, I have a list of foods required.
In Column C, I have the amount needed.
In Column D, I have g (for grams) ml (for mills) etc.
I would like to combine the duplicates in Column B and update the totals from Column C, with the g or ml in Column D beside it.
The list I have has been created by using an array formula based on dropdowns in another sheet.
I have seen people using UNIQUE formula in 1 column (this works) and then a SUMIF formula in another column and then a JOIN formula in another... I tried this but the SUMIF is always returning 0.
Would someone please be able to advise on how I can do this?
TIA :D
It's hard to be sure exactly what you need without seeing the data. But based on my understanding of solely what you've posted, this QUERY formula should generate a condensed mini-report:
=QUERY({B2:D},"Select Col1, SUM(Col2), Col3 WHERE Col1 Is Not Null GROUP BY Col1, Col3 LABEL SUM(Col2) ''")
In plain English, this means "Arrange the data from the range B2:D in the same order as the raw data, but sum the second column's data according to matches in both the first and third columns. Only return results for the raw data where the first column is not blank. Replace the default 'sum' header on the second column with nothing; I don't need it."
This formula assumes that every ingredient will always be attached to the same measurement (e.g., 'salt' in Col B is always paired with 'mg' in Col D, etc.). If this is not the case, you will wind up with ingredients being listed as many times as there are different measures in Col D.

How to query spreadsheet column data, matching and summarising values?

I want to get the total of entries in a column for a particular value. The values are a number such as 0.5 or 1 and then a code such a H, S, O or WFH. i.e "0.5 H" or "1 S"
It is a absence spreadsheet recording holiday, sickness, appointments and working from home. One sheet has a row for every day in the year, the columns represent all the staff members. I wish to be able to query the values under the columns and then summarise that per staff member / per month.
I have googled but not found anything similar enough to put me in the right direction.
Any help would be greatly appreciated.
query function might help you:
about
Query Language Reference
Please, provide data sample to get more help.
your query will look like this:
=query({A:D}, "select Col1, Col2, sum(Col4) where Col3 = '1 S' group by Col1, Col2")
In this sample query formula summarises data in A:D per columns A, B (Col1, Col2) and checks the value in column C (Col3) eqwuals '1 S'.

Trying to include additional columns in QUERY result on GoogleSheets

I'm using Google Sheets and using the following formula without any issue:
=QUERY(Sheet!A:D,"select A, max(B) where not B is null group by A label A 'Client', max(B) 'Most Recent'")
Obviously, this is returning columns A and B of the referenced data
However, I would like to also return the corresponding cells from column C.
sample data: https://docs.google.com/spreadsheets/d/1CJKiDNPUWMMUbLLb-UDA6iRA2PBnlMHDsEB9vELe0Rk/edit?usp=sharing
Using this example, what I would like to see is cell G2 populated with "Pizza" (i.e., from C3), and so on.
Am I using the right formula? What do I need to change?
What you are trying to do is not very SQL-like, because max(B) does not point to any particular row: it's just the maximum value of B among the selected rows. This value could be attained by several rows, making the choice of C, D ambiguous. I don't think that a single query can do this.
Here is an implementation with unique and several query commands.
In E2, enter =unique(A:A) to get the list of unique client names.
In F2, enter
=query(A:D, "select B,C,D where A ='"&E2&"' order by B desc limit 1")
and drag this formula down. This selects all rows with the A value matching E2, and picks one with maximal B value.
You don't want to have a header row in the output of these queries so either add label B '', C '', D '' or just don't include the header row in the queried range.
Version with grouping by C,D
To also select C and D within a single query, expand the select clause
select A, max(B), C, D
which will then require including those in the group by clause:
group by A, C, D
The formula will be
=QUERY(A:D,"select A, max(B), C, D where not B is null group by A, C, D label A 'Client', max(B) 'Most Recent'")
This does mean that the only rows to be grouped together will be those where not only A but also C and D are equal.
A possible one-formula solution:
=ArrayFormula(IFERROR(VLOOKUP(UNIQUE(A2:A),SORT(A2:C,2,0),{1,2,3},0)))
Here is what I did that finally worked.
In E1, enter =unique(A:A) to get the list of unique client names. In F2, enter
=query(A$2:D101, "select B,C,D where A ='"&F2&"' order by B desc limit 1")
and drag this formula down. This selects all rows with the A value matching E2, and picks one with maximal B value.
You don't want to have a header row in the output of these queries so just add desired text in header row.

Resources