How to use an if condition with vlookup? - google-sheets

I am working with some data in google spreadsheets, but I'm having problems with vlookup. I'm trying to get the district of an adress by the name of the street and the house's number. The problem is that vlookup stops on the first row, and some streets are so big that they below for more than one district.
In this example, i want to do a vlookup that returns the district D if my adress is street A number 15. Can someone help me? thanks.
Street
Start_Number
End_Number
District
A
0
10
C
A
11
20
D
B
0
10
C

Try QUERY() instead of VLOOKUP():
=QUERY(A:D, "
SELECT
D
WHERE
A = 'A'
AND B <= 15
AND C >= 15
LABEL
D ''
", 1)
Swap out the 'A' and 15 with cell references if you want it to be dynamic.

Related

Google Sheets: lookup a value in a table then find right most non-blank value in a range

I would like to create a google sheet formula that will lookup the ID and return the right-most non-blank score from columns 'Score A', 'Score B' and Score 'D'. Any help would be much appreciated!
ID
Score A
Score B
Score C
Type
2342
65
43
A
8797
B
2343
23
45
98
F
6666
23
B
2333
67
43
B
Assuming E1 is your search_key here's what you can try:
=LET(ζ,TOROW(XLOOKUP(E1,A2:A,B2:D),1),INDEX(ζ,,COUNTA(ζ)))
You may try:
=ifna(lookup(9^9,xlookup(F1,A:A,B:D)))
You can use the following formula. It concatenates for each row the 3 columns into one string and extracts via regex all characters after the last space.
=VLOOKUP(2342,
{
A:A,
ARRAYFORMULA(IFERROR(REGEXEXTRACT(TRIM(B:B&" "&C:C&" "&D:D),"\b(\w+)$")))
},
2)
Just for adding one more option. It won't matter if they're numbers or not, neither if you have empty cells; it will find the non empty cell most to the right
=LET(r,INDEX(2:1000,XMATCH(E1,A2:A)), INDEX (r,,MAX(COLUMN(r)*(r<>""))))

Google Sheets: Repeat values as rows based on associated numbers

I have a table in Sheets that has 2 columns: (1) Station (2) Number of people at Station:
Station Number of People at Station
A 1
B 2
C 1
D 4
I want to have a new column in excel populate with Station names repeating in it's own row based on number of people at station. The expected output would be below:
Station Allocation
A
B
B
C
D
D
D
D
Is there a way to dynamically have this final table change based on the number of people at station? So if someone was to use a google sheet and they change Station A to 2 people, then there will now be 2 rows with A instead of 1.
Try:
=arrayformula({"Values";query(flatten(if(B2:B<>"",split(rept(A2:A&"|",B2:B),"|"),)),"where Col1 is not null",1)})
Replace "|" with a character that is not used in your dataset.

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.

Search with query formula where cells are not nothing

I have range of cells and want to search with query formula where cells are not nothing.
A B C D
1 a 11 44 qw
2 b 12 r
3 c 13 44 444
4 NOT
5 f 15 55 88
6 NOT
7 h 17 gh ee
Cells in C maybe any number, maybe any word, maybe any nothing.
I want to select everything A where C has nothing.
Result must be:
a
b
c
f
h
When try all the querys formula:
=QUERY(A1:D7,"select A where not C<>'' ")
=QUERY(A1:D7,"select A where not C!='' ")
=QUERY(A1:D7,"select A where not C is null")
=QUERY(A1:D7,"select A where C !='' or not C is null")
Nothing give correct result. Looked everywhere.
What can I do?
Google QUERY function does not work here as "expected" because of mixed data types in column C. If we apply the formula =QUERY(A1:C7;"select A where C is not null";-1)
it will return only "a, c and f". The image below shows this result in column G, where G1 contains the above formula.
We should check data types more carefully, but it is difficult to do inside QUERY function. So I suggest to add one more column (E in our case) and fill it with "=TYPE(C1)" and similar functions. Having data types column, we can modify QUERY expression to take them into account. Final result is shown in column H.
Please check this approach again, if you are going to use other data types in column C.
=QUERY(A1:D7, "select A where C is not null")
...is what you need

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