Query Select Row and Column together one statement - google-sheets

I work on a google sheet, where I should see the number of holidays per day for each team.
The table looks like this:
[table]
A
B
C
D
E
1
Employee Name
Team Name
01/03/2022
02/03/2022
03/03/2022
2
Employee 1
Team A
hol
hol
hol
3
Employee 2
Team B
early
early
early
4
Employee 3
Team A
hol
late
late
5
6
Team A
7
01/03/2022
8
RESULT HERE
I want to have a result that tells me that Team A had on 01/03/2022 2 holidays.
=countif(query(A1:E4,"select C where B contains '"&A6&"'" ),"hol")
A6 contains the team I am looking for.
A7 contains the date I am looking for.
A8 should show me the number of hol.
Currently, I have a fixed column to look inside which is "C". I want to replace that with the date from A7 - How do I do that?
I tried to play around with transpose and filter but had success.

try:
=COUNTIF(FILTER(FILTER(C2:E4, C1:E1=A7), B2:B4=A6), "hol")

Use XMATCH to get the Col number for QUERY and count inside query instead of COUNTIF:
=QUERY(
{B1:E4},
"Select count(Col1)
where Col"&XMATCH(A7,B1:E1)&"='hol'
and Col1='"&A6&"'
label count(Col1) ''",
1
)

Related

How to do a full outer join?

I am trying to do the full join for the data below in two different sheets.
Sheet 9:
Product ID
Name
Quantity
1
addi
55
2
fadi
66
3
sadi
33
Sheet10
Product ID
Variants
Model
1
xyz
2000
2
differ
2001
3
saddd
336
4
fsdfe
2005
Desired output sheet :
Product ID
Name
Quantity
Variants
Model
1
addi
55
xyz
2000
2
fadi
66
differ
2001
3
sadi
33
saddd
336
4
fsdfe
2005
Please also share if we have more columns to join like in sheet 1 and sheet 2 has two more columns like Year, product label etc then what should I change in your proposed solution
I am using this formula but its not returning the desired result
=ARRAYFORMULA({QUERY(SORT(UNIQUE({Sheet9!A1:D; Sheet10!A1:D})), "where Col1 is not null"),IFERROR(VLOOKUP(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SORT(UNIQUE({Sheet9!A1:D; Sheet10!A1:D})), "where Col1 is not null")),,999^99)), TRANSPOSE(QUERY(TRANSPOSE(Sheet9!A1:D),,999^99)), Sheet9!C1:C}, 2, 0),""),IFERROR(VLOOKUP(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SORT(UNIQUE({Sheet9!A1:D; Sheet10!A1:D})), "where Col1 is not null")),,999^99)), {TRANSPOSE(QUERY(TRANSPOSE(Sheet10!A1:D),,999^99)), Sheet10!C1:C}, 2, 0),"")}})
EDITED to consider dynamic row matching.
See this spreadsheet to illustration, but overall there's a question of your setup, but I would break your problem into two steps.
Get distinct list of ID's
You can get that with this formula:
=unique(transpose(split(textjoin(",",true,
iferror(INdex(Sheet2!$A$2:$Z,0,MATCH(A1,Sheet2!1:1,0)),""),
iferror(INdex(Sheet1!$A$2:$Z,0,MATCH(A1,Sheet1!1:1,0)),"")),",")))
Rest of Headers
Then for each header, will they each always only be in 1 exclusively or 2 (not both)? Assuming so, this should work for each additional column. If two values ever exist in the two sheets, will join them in the same column.
=filter(
iferror(VLOOKUP($A$2:$A,Sheet1!$A:$Z,match(E$1,Sheet1!1:1,0),false),"")
&iferror(VLOOKUP($A$2:$A,Sheet2!$A:$Z,match(E$1,Sheet2!1:1,0),false),"")
,$A$2:$A<>"")
There's probably a way to use the join function to do this more elegantly (if someone posts an answer showing me I'll upvote).

Total Sum With Vlookup

I have two spreadsheets with names and times. One is specific session times and on the second sheet, I want to sum up the total times based on each instance from sheet one.
Sheet 1: Session Time
Name | Time
David 5
Mike 2
Daniel 3
David 2
Daniel 8
Sheet 2: Total Time (The one for which I need a forumula)
Name | Total Time
David 7
Mike 2
Daniel 11
I tried a countif and vlookup but I couldn't get it match more than one instance of the name on sheet 1. I also tried this suggested formual from a suggested post but its not summing a second instance of the user name
=ARRAYFORMULA(SUM(ifna(VLOOKUP(A2, 'Sheet 1'!A3:AA16, 5, false))))
A2 = David (On Sheet 2)
Sheet 1'!A3:AA16 = List of names in columns A and all the way to AA is a series of columns with numerical values
5 = the column number from with I want to return the sum for every instance of David (2 in this example with a total of 7)
False = its not sorted
Any help is mucho appriciado!
You can use this formula in your Sheet2!B1:
={"Total Time";arrayformula(if(A2:A<>"",sumif(Sheet1!A1:A,A2:A,Sheet1!B1:B),""))}
Or simply use =arrayformula(if(A2:A<>"",sumif(Sheet1!A1:A,A2:A,Sheet1!B1:B),"")) in Sheet2!B2
Get the sum of the range based on a specific criteria using SUMIF()
Basically, get the sum of Sheet1!B1:B if Sheet1!A1:A matches the current cell being checked in arrayformula A2:A
Output:
This can be accomplished with a simple QUERY, e.g.,
=QUERY('Session Time'!A:B, "Select A, SUM(B) WHERE A Is Not Null GROUP BY A LABEL SUM(B) 'Total Time'")

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.

Query : sum for all key containing given substring

I have the following table:
A
B
Luka, Jean
1
Luka
2
Jean
3
Luka, Jean, Etienne
4
Luka, Jean
5
I would like to have the sum total of every lane containing the name "Luka" and the name "Jean". I am able to have this result but for each unique key containing these names.
My query is : =QUERY(A1:B,"select A, sum(B) where A contains 'Luka' and A contains 'Jean' group by A")
The result is:
sum
Luka, Jean
1
Luka, Jean, Etienne
4
However I would like to have the total result for this query in one unique cell. I think I need to have nested queries but I don't know how to do it.
Expected result :
5 (in one cell without any header or key)
You can try =INDEX(QUERY(QUERY(A1:B,"select A, sum(B) where A contains 'Luka' and A contains 'Jean' group by A"), "select sum(Col2)", 1), 2)
or an actually easier way using your formula itself =INDEX(QUERY(A1:B,"select sum(B) where A contains 'Luka' and A contains 'Jean'"), 2)
First, it seems to me that the total given the sample data in your post should be 10, not 5 (it seems you were not including row 5 for some reason).
Assuming I am correct:
=SUM(FILTER(B:B,ISNUMBER(SEARCH("Luka",A:A)*SEARCH("Jean",A:A))))

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