I want to run a lookup function in Google Sheets that takes multiple conditions
- User
I want to run a lookup function in Google Sheets that takes multiple conditions
- Assistant
In Google Sheets, you can use the
FILTERfunction to perform a lookup with multiple conditions. TheFILTERfunction allows you to filter a range based on specified conditions, returning the rows or columns that meet those conditions.Here's a general syntax for the
FILTERfunction:FILTER(range, condition1, condition2, ...)For example, let's say you have the following data in a sheet:
A B C 1 Name Category Score 2 Alice A 75 3 Bob B 80 4 Carol A 85 5 Dave B 90If you want to find the score of a person in Category A with a score greater than 80, you would use the
FILTERfunction as follows:=FILTER(C2:C5, B2:B5="A", C2:C5>80)This formula will return the score 85, which is Carol's score.
If you expect multiple values to meet the conditions, the
FILTERfunction will return an array of values. You can wrap theFILTERfunction with other functions to manipulate the results further, such asSUM,AVERAGE, orMAX.Keep in
- User
I want to run a VLOOKUP where I check if my search_key is between two values in my lookup range
- Assistant
To perform a VLOOKUP where the search_key falls between two values in the lookup range, you can use the
INDEXandMATCHfunctions instead of theVLOOKUPfunction. TheMATCHfunction is used to find the position of the search_key within a specified range, while theINDEXfunction retrieves the value at the given position in the specified range.Here's a general syntax for this approach:
=INDEX(return_range, MATCH(search_key, lookup_range, 1))For example, let's say you have the following data in a sheet:
A B C 1 Min Max Category 2 0 50 Low 3 51 100 Medium 4 101 200 HighIf you want to find the category for a value, such as 75, you would use the
INDEXandMATCHfunctions as follows:=INDEX(C2:C4, MATCH(75, B2:B4, 1))This formula will return "Medium" because 75 falls between 51 and 100.
Note that the lookup range (B2:B4 in this example) should be sorted in ascending order for this method to work correctly. The third argument in the
MATCHfunction,1, means that the function will look for the largest value that is less than or equal - User
Is it possible to run an =INDEX, MATCH function to search a condition across multiple columns?
- Assistant
Yes, you can use the
INDEXandMATCHfunctions to search for a condition across multiple columns. To do this, you'll need to use an array formula and combine theMATCHfunction with an array of multiple ranges. Here's a general syntax for this approach:=INDEX(return_range, MATCH(1, (search_key = lookup_range1) * (search_key = lookup_range2), 0))For example, let's say you have the following data in a sheet:
A B C 1 Name Category Score 2 Alice A 75 3 Bob B 80 4 Carol A 85 5 Dave B 90If you want to find the row number where the name is "Alice" and the category is "A", you would use the
INDEXandMATCHfunctions as follows:=INDEX(ROW(A2:A5), MATCH(1, (A2:A5="Alice") * (B2:B5="A"), 0))This formula will return 1, which is the relative row number of Alice within the given range (A2:A5). Note that the formula above is an array formula, so you need to enter it using
Ctrl+Shift+Enterrather than just pressingEnter. When you do this, Google Sheets will automatically wrap the formula in - User
Let's use an example where column A = min and column B = max where the values make up a range of scores like in your example above
A B C 1 Min Max Category 2 0 50 Low 3 51 100 Medium 4 101 200 High Let's make column C titled "Class" which has values = Art, History, Geography
Column D is titled "Comment" and holds the comments that the teacher will put on the student's paper. The values for Comment are ("Great Job", "Super", "Fantastic")
I have a column F with Scores of the students and column G with Class values. I want to use the scores in Column F to find the proper row based on the Min and Max columns where my score should be between the Min and Max. Once I have found this row, I will use my Class values in column G to look for a match in column C in order to find the proper Comment value for the Score and Class results
- Assistant
To achieve this, you can use a combination of
INDEX,MATCH, andIFfunctions in an array formula. Here's a step-by-step example based on the data you provided:A B C D 1 Min Max Class Comment 2 0 50 Art Great Job 3 51 100 Art Super 4 101 200 Art Fantastic 5 0 50 History Great Job 6 51 100 History Super 7 101 200 History Fantastic 8 0 50 Geography Great Job 9 51 100 Geography Super 10 101 200 Geography FantasticLet's say the student scores are in column F (starting from F2) and the class values are in column G (starting from G2). You can use the following formula to find the proper comment value for the score and class results:
=INDEX($D$2:$D$10, MATCH(1, (F2 >= $A$2:$A$10) * (F2 <= $B$2:$B$10) * (G2 = $C$2:$C$10), 0))Remember to enter this formula as an array formula using
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.