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
You can do this by using a combination of INDEX, MATCH and IF functions. Here’s an example:
=IF(MATCH(F2, INDEX(A:B, 0, MATCH(G2, C:C, 0)):INDEX(A:B, MATCH(1E+99, A:A), MATCH(G2, C:C, 0)), 1) > 0, "Great Job", IF(MATCH(F2, INDEX(A:B, 0, MATCH(G2, C:C, 0)):INDEX(A:B, MATCH(1E+99, A:A), MATCH(G2, C:C, 0)), 2) > 0, "Super", IF(MATCH(F2, INDEX(A:B, 0, MATCH(G2, C:C, 0)):INDEX(A:B, MATCH(1E+99, A:A), MATCH(G2, C:C, 0)), 3) > 0, "Fantastic", "")))
This formula will use the MATCH function to find the position of the input score F2 in the range of scores defined by the Min and Max columns (A:B) corresponding to the class (G2). It then uses the IF function to determine the value of the comment based on the position of the score within the range.
Please note that this formula will only work if the values in your Min, Max and Class columns are unique and in the same order as in the example you've provided.
Also, this is just a basic example and it will only work with 3 classes, if you have more classes you can use the array form of INDEX and MATCH and add more IFs for the comment.
Let me know if you have any questions regarding this formula.
Confidence: 90%
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.