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
What sort of lookup function are you trying to run?
- User
I want to run a VLOOKUP where I check if my search_key is between two values in my lookup range
Assistant
You’re trying to find the range of values in your table that are between two values in your search_key? You can do that with a “=INDEX,MATCH” function.
- User
Is it possible to run an =INDEX, MATCH function to search a condition across multiple columns?
Assistant
Yes, you can use an INDEX,MATCH function to find the range of values in your table that meet a condition across multiple columns. For example, you could search for values that are between two values in your search_key in columns A and B, and return the value in column C.
- 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
Here's an example formula to use in cell G2:
=INDEX(C:C, MATCH(G1, B:B, 0), MATCH(F1, A:A, 0))
This formula uses INDEX and MATCH to find the row in the "Class" column that matches the value in cell G1 (the score) and the row in the "Comment" column that matches the value in cell F1 (the class). The formula first finds the row in the "Class" column that matches the value in cell G1 using MATCH with the range B:B for the lookup values and 0 for the match type (exact match). The result of this match is used as the row number in the INDEX function to retrieve the value from the "Comment" column that matches the value in cell F1 using MATCH with the range A:A for the lookup values and 0 for the match type (exact match). The result of this match is used as the column number in the INDEX function to retrieve the value from the "Comment" column.
So, if cell G1 contains a score between 2 and 4, the formula will look for a match in column B between 2 and 4 and return the corresponding value from column C (Low). If cell F1 contains the value Art, the formula will look for a match in column A between Art and return the corresponding value from column G (Great Job). The result is the appropriate comment for the score and class combination.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.