Query to View only top counts and counted by group - google-sheets

I wanted to use this query
=query(G2:I80,"select G,H,I where H=max(H) group by I",-1)
From this:
Cdd Cts T
NWH 4 A1
LBB 3 A1
MP 3 A1
DC 2 A1
AK 10 A10
CC 3 A10
SC 2 A11
JL 1 A11
VT 1 A11
To This:
T Cdd Cts
A1 NWH 4
A10 AK 10
A11 SC 2
Am I doing it right? Or I have to come up with something to manually count them?

Try
=ArrayFormula(iferror(vlookup(unique(I2:I), sort({I2:I, G2:H},3,), {1,2,3},0)))
and see if that works for you ?
How does it work:
1: with sort() a new 'virtual' table is created with col I as the first column. That new table is sorted on col H (latest dates appear on top).
2: a list with the unique values is retrieved from col I (with the unique function)
3: that list is 'looked up' (with vlookup). When a match is found it retrieves the first 3 columns ({1, 2, 3} or: col I, G and H). Vlookup only returns the first match found: since our list is sorted, that will be the entry with the latest date.
4: if nothing is found an error is suppressed with the iferror().

Related

Google Sheets: Query and list the last 5 values in a column if the column contains a number

I want to use Sparkline for a spreadsheet to show a trend of the last 5 soccer matches, where A and B are the goals, and C are the resulting points.
In column C, the points are only generated if values are entered for the goals and goals conceded, i.e. the columns are not empty.
A (Goals)
B (Conceded)
C (Points)
4
4
1
4
4
1
4
4
0
3
4
4
1
0
4
0
As you see, in row 3, column c is empty.
What I basically try to achieve, is to create a list where the last 5 entries which are not empty / null, are listed:
C (Points)
1
1
3
1
0
Is used this formula, but it somehow does not work
=query(J15:J114,"select * offset "&count(J15:J114)-5)
shorturl.at/gHPY9 (example result picture)
Tried to find a solution myself, but am stuck.
Best,
Feal
Use query() with a where clause, like this:
=query(
J15:J114,
"where J is not null
offset " & max(0, count(J15:J114) - 5),
0
)

Count number of rows for each type in google spreadsheet

A B C
1 4 Apple
2 5 Orange
3 6 Apple
1 4 Orange
2 4 Apple
3 4 Banana
I want to count each type of column C(if possible also plot it), ie output should be
Apple 3
Orange 2
Banana 1
Just more to a new columns and paste the folloing in its header:
=query(H2:H,"select H, count(H) where H != '' group by H order by count(H) desc label H 'Fruit'", 0)
It is show something like your expection in new two columns beside the original data
As an alternative to the solution already provided, you can make use of UNIQUE and COUNTIF.
Use UNIQUE in order to extract the names for each fruit from the C column
=UNIQUE(C1:C)
Use COUNTIF within an ARRAYFORMULA in order to count the number of times each fruit is present in the C column and later drag it down the E column:
=ARRAYFORMULA(COUNTIF(C1:C,D1))
Reference
UNIQUE Function;
COUNTIF Function.

Sheets: Count Row data Based on Key

Im trying to find a Row based on a value, and count the number of entries (Max 5) in that row.
A
B
C
D
E
F
G
1
John
2
2
5
4
2
Mary
1
3
1
6
7
=COUNTA(B1:GZ) will work if I knew the row for "John",
but im trying to get the row based on a value from another cell ...
Z
10
John
In this case Z10 pseudo: =COUNTA(Find Z10 in Col A, then count entries in Row starting at B to Z)
Any ideas ? Thanks.
Recommendation:
You can try this method
=COUNTA(QUERY(A1:Z, "Select * where A = '"&Z10&"'"))-1
Sample
Sample sheet:
John added on cell Z10
The recommended function added on cell Z11
Result: 4 was the result of COUNTA on the rows B:Z based on Column A that contains the value "John"
NOTE:
You may need to turn on Iterative calculation on your Spreadsheet settings.

Sum of a range of cells that may contain + sign

I have a google sheet table with the cells A1, B1 and C1 containing
either an integer, e.g., 12 or an expression <integer> + <integer>, e.g., 12 + 1 or 12+1.
I want to compute the sum of the cells in D1. Situation
|A1| B1 | C1|
--------------
|1 | 1+1 | 3 |
should result in 6. Simply saying D1 = SUM(A1:C1) does not work:
it ignores the cell B1.
I have found two partial solutions that I cannot combine:
SUM(SPLIT(B1;"+")) results in 2
if I had A2: 1, B2: 4 and C2: 9, then ArrayFormula(SUM(SQRT(A2:C2))) results in 6 (sum of square roots of these cells).
(e.g., ArrayFormula(SUM(SUM(SPLIT(A1:C1;"+")))) does not work properly)
How can I solve this problem? Two-step solution i) compute SUM(SPLIT(<cell>;"+")) in a new cell, and ii) compute the sum, is not an option.
Try this:
=SUM(SPLIT(JOIN("+",A1:C1),"+"))
In this solution you just need to join them first.
BTW this formula works too:
=SUM(SPLIT(JOIN("+",A1:C1),"+:)"))

How to use QUERY in Sheets to find most recent grade for each student?

I have a spreadsheet containing a list of assessments for students. It is comprised of four columns:
A B C D
Student Standard Date Score
On another sheet I have a table containing a list of students in column A and a list of standards in Row 1.
I want to query the spreadsheet of assessments to return the score of the most recent assessment for the current student on the current standard. Currently I have this formula in cell K3:
=Query(Assessments!A:D,"select D where(A="&$A3&" and B="&K$1&") order by max(C) limit 1")
but it gives me this error:
Unable to parse query string for Function QUERY parameter 2: AGG_IN_ORDER_NOT_IN_SELECTMAX(C)
Edit:
I've gotten some great answers, but I guess I asked poorly. What I really need is the score from the most recent assessment. The results from JPV and pnuts have both given the date of the most recent assessment. Here is a stripped down version of the actual file: spreadsheet.
In the Students sheet I'm needing a formula in the Green cells that results in a number from 0 to 4 based on the data in the Assessments sheet.
This is why in the query I was trying to select D, but order by max(C).
I tweaked one of these formulas and got:
=iferror(query(A3:D20, "Select D where A = '"&G20&"' and B = '"&I20&"' order by C desc limit 1",0), "no data found")
I addition to the fine solution provided by pnuts (+1 for the sample data), here are some posibilities using query (check the green cells in this spreadsheet.
=query(A2:D20, "select A, MAX(C) GROUP BY A pivot B",1)
or
=query(A2:D20, "select A, B, MAX(C) GROUP BY A, B",1)
should create a table with the latest date per student, per standard.
In case you want to use cell references (where a cell holds a student name and another cell holds the standard), try:
=iferror(query(A3:D20, "Select A, B, C where A = '"&G20&"' and B = '"&I20&"' order by C desc limit 1",0), "no data found")
where G20 is student name and I20 is standard (change range to suit).
Does not use the query function but seems to "query the spreadsheet of assessments to return the most recent assessment for the current student on the current standard":
=iferror(max(filter(Assessments!$A$1:$D$99,Assessments!$A$1:$A$99=$A3,Assessments!$B$1:$B$99=K$1)),"")
Constructed data as example:
Student Standard Date Score
Bod5 C 2/2/2015 9
Bod6 B 1/1/2015 8
Bod7 C 7/7/2015 7
Bod8 A 9/9/2015 6
Bod1 B 3/3/2015 5
Bod2 C 4/4/2015 43
Bod3 B 6/6/2015 2
Bod4 C 1/1/2015 1
Bod1 A 1/1/2016 8
Bod1 A 2/2/2017 7
Bod1 A 1/1/2013 6
Bod1 A 1/1/2011 5
Bod9 A 9/9/2009 9
Bod9 B 1/1/2011 3
Bod9 C 3/3/2013 2
Bod9 A 10/10/2010 4
Bod9 B 11/1/2001 2
Bod9 C 4/4/2014 1
Output:

Resources