# How to use VLOOKUP/XLOOKUP with multiple conditions

I will in this article demonstrate how to use the VLOOKUP function with multiple conditions. The function was not built for these circumstances, however, I will demonstrate a few workarounds and also explain how they work.

There is a file for you to get at the very end of this article.

### Table of Contents

**VLOOKUP examples**

- VLOOKUP function with two conditions applied to two columns (AND logic)?
- VLOOKUP function with two conditions applied to two columns (OR logic)?
- VLOOKUP function with many conditions applied to one column (OR logic)?
- Can we use VLOOKUP with multiple lookup values?
- VLOOKUP across multiple columns?
- Can you concatenate VLOOKUP results?
- How to use VLOOKUP with dates?
- What if I don't have the lookup column in the left-most column?
- VLOOKUP - Select column using a drop-down list
- Why do I want to convert the data set to an Excel Table?
- VLOOKUP in a filtered Excel Table and return multiple values

**XLOOKUP examples**

- XLOOKUP - two conditions in two columns (AND logic)?
- XLOOKUP - two conditions in two columns (OR logic)?
- XLOOKUP - multiple conditions in one column (OR logic)?
- Can we use XLOOKUP with multiple lookup values?
- XLOOKUP across multiple columns?
- Can you concatenate XLOOKUP results?
- How to use XLOOKUP with dates?
- What if I don't have the lookup column in the left-most column?

## 1.1 How to use the VLOOKUP function with two conditions (AND logic)?

The image above shows a data set in cell range B2:F12, the VLOOKUP function in cell D16 looks for both a value in column B and another value in column C. If both values match a third value on the same row is retrieved from column D and shown in cell D17.

AND logic means that the VLOOKUP function retrieves only if both conditions match.

#### Can you combine the IF function and the VLOOKUP function?

Yes, you can, in fact, it is the easiest way to VLOOKUP using two or more conditions.

Array formula in D17:

To enter an array formula press and hold CTRL + SHIFT simultaneously, then press Enter once. Release all keys.

The formula bar now shows the formula enclosed with curly brackets telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

### Explaining formula in cell D17

I recommend you use the "Evaluate Formula" feature in Excel to examine calculations step by step.

Select cell D17, go to tab "Formulas" on the ribbon and press with left mouse button on the "Evaluate Formula" button.

(*The formula shown in the above image is not the formula used in this article.*)

Press with left mouse button on "Evaluate" button to see the next step in the formula calculations.

#### Step 1 - Filter records

The IF function filters records that match the value in cell D15, all remaining records are blank. The IF function has three arguments: IF(*logical_test*, [*value_if_true*], [*value_if_false*])

The logical_test argument is C3:C12=D15, it checks if the values in column C are equal to the condition in cell D15. TRUE is returned if it is equal and FALSE if not equal.

IF(C3:C12=D15, B3:F12, "")

returns {"","","",... ,"Hennessey"}

This array has commas and semicolons as delimiting characters, the picture below shows the array in cell range B3:F12. It is now obvious that the IF function has filtered records containing ony the condition.

#### Step 2 - VLOOKUP value and return value from column to cell D16

VLOOKUP(D14,IF(C3:C12=D15,B3:F12,""),3,FALSE)

returns "The New Firm" in cell D16.

## 1.2 How to use the VLOOKUP function with two conditions applied to two columns (OR logic)?

This example demonstrates a formula that returns a value from a record that matches at least one of the two conditions, that is why it is called OR logic.

It becomes quite quickly obvious that the VLOOKUP function is not built for more advanced criteria, I am not using the VLOOKUP function in this example, to keep the formula as small as possible.

Array formula in cell D17:

To enter an array formula press and hold CTRL + SHIFT simultaneously, then press Enter once. Release all keys.

The formula bar now shows the formula enclosed with curly brackets telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

If you are looking for a non-array formula here is one:

This formula returns a value from the last matching record contrary to the first formula above that returns a value from the first matching record.

### Explaining formula in cell D17

#### Step 1 - First condition

The first condition is specified in cell D14, to compare that value with the values in cell range B3:B14 I use the equal sign. It is a logical operator that returns TRUE or FALSE after the evaluations is made.

We are performing multiple calcualtions in one cell and this is the reason we need to enter this as an array formula.

B3:B12=D14

returns {TRUE; FALSE; FALSE; ... ; FALSE}

#### Step 2 - Second condition

C3:C12=D15

returns {FALSE; FALSE; FALSE; ... ; TRUE}

#### Step 3 - Add arrays to apply OR logic

The plus sign adds the two arrays row-wise, TRUE + TRUE = 2, TRUE + FALSE = 1 and FALSE + FALSE = 0

((B3:B12=D14)+(C3:C12=D15))>0

returns {TRUE; FALSE; FALSE; ... ; TRUE}

#### Step 4 - Identify the position

The MATCH function, as it is set up in this example, returns the relative position of the first found matching value based on an exact match.

MATCH(TRUE,((B3:B12=D14)+(C3:C12=D15))>0,0)

returns 1.

#### Step 5 - Return the corresponding value

The INDEX function returns a value based on a row and column number.

INDEX($D$3:$D$12, MATCH(TRUE, ((B3:B12=D14)+(C3:C12=D15))>0, 0))

returns "Atlantic Corporation" in cell D17.

## 1.3 How to use the VLOOKUP function with many conditions applied to one column (OR logic)?

This example demonstrates how to use multiple conditions and the formula returns a value from the first record that matches any of the conditions.

The following formula does not use the VLOOKUP function, it is possible to build such formula but it will be complicated and much larger than needed.

Array formula in cell D17:

To enter an array formula press and hold CTRL + SHIFT simultaneously, then press Enter once. Release all keys.

The formula bar now shows the formula enclosed with curly brackets telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

### Explaining formula in cell D17

#### Step 1 - Check values that match

The COUNTIF function counts values that equal a condition, however, it can also count multiple conditions but we must enter this formula as an array formula in order to calculate multiple values in one cell.

COUNTIF(D14:D15, B3:B12)>0

returns

{0;0;1;1;0;0;1;1;0;0}.

This array has as many values as there are values in cell range B3:B12, the values also corresponds to B3:B12. 0 (zero) indicates that the value is not equal to "C" or "D" and 1 shows that the value is equal to "C" or "D".

#### Step 2 - Find the position of the record

The MATCH function, as it is set up in this example, returns the relative position of the first found matching value based on an exact match.

MATCH(1, COUNTIF(D14:D15, B3:B12), 0)

returns 3. The first value that is equal to 1 is in 3rd position in the array.

#### Step 3 - Return corresponding value

The INDEX function returns a value based on a row and column number, the cell range is in a column only, we don't need to specify the column number.

INDEX($D$3:$D$12, MATCH(1, COUNTIF(D14:D15, B3:B12), 0))

returns "Omni Consumer Products".

## 1.4 How to use VLOOKUP function with multiple lookup values?

This example demonstrates how to use multiple lookup values in the VLOOKUP function, the lookup values are in cell D14 and D15.

The lookup values are found in row 5,6,9 and 10 but only the corresponding values from row 5 and 6 are returned, that is how the VLOOKUP function is supposed to work. If you need to extract multiple values based on a condition read this: 5 easy ways to VLOOKUP and return multiple values

Array formula in cell D14:D15:

This is an array formula, it returns multiple values. We need to enter it in multiple cells at once, here is how to do it.

Select cell range D14:D15, press with left mouse button on in the formula bar to see the prompt. Copy and paste above array formula to formula bar.

The VLOOKUP function demonstrated above has two lookup values which is fine as long as you enter it in as many cells as there are lookup values.

The downside with this formula is that it only extracts one return value per lookup value, read this article: Vlookup with 2 or more lookup criteria and return multiple matches

## 1.5 VLOOKUP across multiple columns?

Unfortunately, the VLOOKUP function can't look in other columns than the left-most column in a cell range. We need to use other functions to accomplish that.

The image above demonstrates an array formula in cell D17 that returns a value from column D (Company Name) if the corresponding value on the same row in column B or C matches the specified value in cell D17.

Array formula in cell D17:

### Explaining formula in cell D17

#### Step 1 - Compare values to the lookup value

The equal sign lets you check if a cell value is equal to another value, the difference with this setup is that it compares a cell value to a cell range.

In this case B3:C12, this is fine as long as you enter the formula as an array formula. The formula performs multiple calcualtions in one cell, the result is an array containing boolean values, TRUE or FALSE.

B3:C12=D14

returns {FALSE,FALSE; TRUE,... ,FALSE}

#### Step 2 - Replace boolean values with corresponding row number

The IF function allows you to change the array based on if the logical expression returns TRUE or FALSE.

IF(B3:C12=D14,MATCH(ROW(B3:B12),ROW(B3:B12)),"")

returns {"",""; 2,... ,""}

#### Step 3 - Extract the smallest row number

The MIN function returns the samllest number from an cell range or array.

MIN(IF(B3:C12=D14,MATCH(ROW(B3:B12),ROW(B3:B12)),"")

returns 2.

#### Step 4 - Return value

The INDEX function returns a value from a cell range or array based on a row and column number. Our example has only a single column so the column number is not needed.

INDEX($D$3:$D$12,MIN(IF(B3:C12=D14,MATCH(ROW(B3:B12),ROW(B3:B12)),"")))

returns "Uplink Corporation".

## 1.6 Can you concatenate VLOOKUP results?

No, you can't concatenate multiple return values from a VLOOKUP function. It will only return one instance. This example shows how to concatenate multiple values using multiple conditions using the TEXTJOIN, IF and COUNTIF functions.

Array formula in cell D17:

### Explaining formula in cell D17

#### Step 1 - Determine which records match the conditions

The COUNTIF function counts values equal a condition or in this case multiple conditions.

COUNTIF(D14:D15,B3:B12)

returns {0; 0; 1; ... ; 0}.

#### Step 2 - Replace array with values

The IF function allows you to change the array based on if the logical expression returns TRUE or FALSE.

IF(COUNTIF(D14:D15,B3:B12),D3:D12,"")

returns

{"";"";"Omni Consumer Products";... ;""}

#### Step 3 - Concatenate values

The TEXTJOIN function allows you to concatenate a cell range or array, you can choose the delimiting character and if you want to ignore blank values.

TEXTJOIN(", ",TRUE, IF(COUNTIF(D14:D15,B3:B12),D3:D12,""))

returns "Omni Consumer Products, Galaxy Corp".

## 1.7 How to use VLOOKUP with dates?

This example shows how to VLOOKUP using a condition, start and end date. The formula returns a value from the first record that matches all three conditions.

Array formula in cell C5:

### Explaining formula in cell C5

#### Step 1 - Identify rows with dates larger than the start date

This logical expression checks whether the dates in column Date are bigger (later) than the start date in cell C3.

Table3[Date]>=C3

returns {FALSE; TRUE; TRUE;... ; TRUE}

#### Step 2 - Identify rows with dates smaller than the end date

The following logical expression checks whether the dates in column Date are smaller (earlier) than the end date in cell C3.

Table3[Date]<=C4

returns {TRUE;TRUE;TRUE;... ;FALSE}

#### Step 3 - Multiply arrays

We want to know if both conditions are met, to do that we must multiply the arrays. TRUE * TRUE = TRUE (1), TRUE * FALSE = FALSE (0), FALSE * FALSE = FALSE (0)

(Table3[Date]>=C3)*(Table3[Date]<=C4)

returns {0;1;1;1;1;1;1;0;0;0}

#### Step 4 - Filter records that match

The IF function filters records that match both conditions.

IF((Table3[Date]>=C3)*(Table3[Date]<=C4),Table3,"")

returns {"","","",... ,""}.

#### Step 5 - VLOOKUP using the array

The VLOOKUP function uses the array returned from the IF function and looks for the lookup value in the left-most column in the array.

VLOOKUP(C2,IF((Table3[Date]>=C3)*(Table3[Date]<=C4),Table3,""),3,FALSE)

returns "The New Firm"

## 1.8 What if I don't have the lookup column in the left-most column?

The VLOOKUP function can only look for values in the first column of the table_array. The formula below demonstrates how to do a lookup in any table column and return a value from any table column.

The INDEX and MATCH function is more versatile than VLOOKUP and it is easier to apply more conditions if needed, however, it still can only return one value even if there are more records that match. The INDEX, SMALL and IF function can return multiple values, read this article: 5 easy ways to VLOOKUP and return multiple values

Formula in cell C3:

Learn more about the INDEX and MATCH functions:

Recommended articles

Gets a value in a specific cell range based on a row and column number.

Recommended articles

Identify the position of a value in an array.

becomes

INDEX(Table4[Item],4)

becomes

INDEX({"A"; "B"; "C"; "D"; "A"; "B"; "C"; "D"; "E"; "F"},4)

and returns D in cell C3.

## 1.9 VLOOKUP - Select column using a drop-down list

The worksheet shown above lets you select the column using a drop-down list from which you want the return value, this way you don't need to edit the formula when you need data from another column.

Array formula in cell C4:

#### How to create the drop down list in cell B4

- Select cell B4
- Go to "Data" tab
- Press with left mouse button on "Data Validation" button
- Select "List" i the drop down list
- Select source: =$C$8:$E$8

- Press with left mouse button on OK

### Explaining formula in cell C4

#### Step 1 - Find the relative position

The MATCH function returns the relative position of an item in an array that matchesÂ a specified value in a specific order.

Function syntax: MATCH(lookup_value, lookup_array, [match_type])

MATCH(B4, Table2[#Headers], 0)

returns 3.

#### Step 2 - Logical test

The equal sign is a logical operator, it lets you compare a value to another value in an Excel formula. The result is a boolean value, TRUE or FALSE.

You can use the equal sign to compare a value to a cell range of values as well.

Table2[Region]=C3

returns {FALSE; FALSE; FALSE; ... ; TRUE}

#### Step 3 - Filter values based on a condition

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

Function syntax: IF(logical_test, [value_if_true], [value_if_false])

IF(Table2[Region]=C3, Table2, "")

returns {"","","",... ,"Hennessey"}

#### Step 4 - Perform a lookup

The VLOOKUP function lets you search the leftmost column for a value and return another value on the same row in a column you specify.

Function syntax: VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

VLOOKUP(C2, IF(Table2[Region]=C3, Table2, ""), MATCH(B4, Table2[#Headers], 0), FALSE)

returns "The New Firm".

## 1.10 Why do I want to convert the data set to an Excel Table?

If you convert your cell range to a table you can add or remove as many records to the Excel table as you want and the cell reference in the formula is automatically adjusted.

Use the table name and table column name in the VLOOKUP function to achieve this, see the formula bar in the picture above.

#### How to convert a cell range to an Excel defined Table?

- Select any cell in your data set.
- Go to tab "Insert" on the ribbon.
- Press with left mouse button on "Table" button to open a dialog box.

- Enable "My table has headers".
- Press with left mouse button on OK.

Learn more about excel tables:

Recommended articles

An Excel table allows you to easily sort, filter and sum values in a data set where values are related.

## 1.11 VLOOKUP in a filtered Excel Table and return multiple values

This section describes how to search filtered values in an ExcelÂ defined TableÂ using a condition given in cell 12 and return multiple values. Some rows are hidden because of Excel Table filters, I am not using the VLOOKUP function in this formula.

Excel 365 dynamic array formula in cell B15:

Array Formula in cell B15:

#### How to create an array formula

- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar.

- Press and hold Ctrl + Shift.
- Press Enter once.
- Release all keys.

#### Filter table

Let's remove all A's from item column. Press with left mouse button on black arrow near Item header. Deselect A. Press with left mouse button on OK.

### Explaining formula in cell B15

#### Step 1 - Create array

This step is necessary in order to be able to use the SUBTOTAL function in the next step. The ROW function returns row numbers based on a cell reference.

The MATCH function converts the row number array to an array that starts with 1.

OFFSET(Table1[Number], MATCH(ROW(Table1[Number]), ROW(Table1[Number]))-1, 0, 1)

returns {2; 1; 2; 1; 2; 1; 2}.

#### Step 2 - Which values are shown in the Filtered Excel table

The SUBTOTAL(103, array) counts the number of values that are not empty.

SUBTOTAL(103, OFFSET(Table1[Number], MATCH(ROW(Table1[Number]), ROW(Table1[Number]))-1, 0, 1))

returns {0; 1; 1; 0; 1; 1; 0; 1}

This array may look weird, the array in the SUBTOTAL function has 7 values and the result array has 8 values, how is it possible? This is, however, what you get if you convert the functions to constants by selecting them using and then pressing F9.

If you examine the formula using the "Evaluate Formula" tool you get the following array: {#VALUE!;Â #VALUE!;Â #VALUE!;Â #VALUE!;Â #VALUE!;Â #VALUE!;Â #VALUE!;Â #VALUE!}

Even more confusing.Â This is what I think is going on. The OFFSET function actually returns an array of arrays, like this { {2}; {1}; {2}; {1}; {2}; {1}; {2} }

Then the SUBTOTAL function returns an array that indicates if the value is shown in the filtered table or not. 0 (zero) means not shown and 1 is visible.

{0; 1; 1; 0; 1; 1; 0; 1} meaning row 3, 6 and 9 are hidden in the filtered table.

#### Step 3 - Convert array to actual values

TheÂ IF functionÂ has three arguments, the first one must be a logical expression. If the expression evaluates to TRUE then one thing happens (argument 2) and if FALSE another thing happens (argument 3).

IF(SUBTOTAL(103, OFFSET(Table1[Number], MATCH(ROW(Table1[Number]), ROW(Table1[Number]))-1, 0, 1)), Table1[Number])

returns {FALSE; 2; 1; FALSE; 1; 2; FALSE; 2}

#### Step 4 - Match values to condition specified in cell C12

IF($C$12=(IF(SUBTOTAL(103, OFFSET(Table1[Number], MATCH(ROW(Table1[Number]), ROW(Table1[Number]))-1, 0, 1)), Table1[Number])), MATCH(ROW(Table1[Number]), ROW(Table1[Number])), "")

returns {""; ""; 3; ""; 5; ""; ""; ""}

#### Step 5 - Extract k-th smallest row number

To be able to return a new value in a cell each I use theÂ SMALL functionÂ to extract row numbers from smallest to largest.

TheÂ ROWS functionÂ keeps track of the numbers based on an expanding cell reference. It will expand as the formula is copied to the cells below.

SMALL(IF($C$12=(IF(SUBTOTAL(103, OFFSET(Table1[Number], MATCH(ROW(Table1[Number]), ROW(Table1[Number]))-1, 0, 1)), Table1[Number])), MATCH(ROW(Table1[Number]), ROW(Table1[Number])), ""), ROWS($A$1:A1))

returns 3.

#### Step 6 - Return value based on row number

TheÂ INDEX functionÂ returns a value based on a cell reference and column/row numbers.

INDEX(Table1[Result], SMALL(IF($C$12=(IF(SUBTOTAL(103, OFFSET(Table1[Number], MATCH(ROW(Table1[Number]), ROW(Table1[Number]))-1, 0, 1)), Table1[Number])), MATCH(ROW(Table1[Number]), ROW(Table1[Number])), ""), ROWS($A$1:A1)))

returns A30 in cell B15.

## 2.1 XLOOKUP function with two conditions applied to two columns (AND logic)?

Excel 365 formula in cell D17:

### Explaining formula

#### Step 1 - First condition

The equal sign is a logical operator, it lets you compare a value to another value in an Excel formula. The result is a boolean value, TRUE or FALSE.

You can use the equal sign to compare a value to a cell range of values as well.

B3:B12=D14

returns {TRUE; FALSE; FALSE; ... ; FALSE}.

#### Step 2 - Second condition

C3:C12=D15

returns {FALSE; FALSE; FALSE; ... ; TRUE}.

#### Step 3 - Apply AND logic

The parentheses let you control the order of operation. We need to calculate the comparisons before we multiply the arrays.

(B3:B12=D14)*(C3:C12=D15)

returns {0;0;0;0;1;0;0;0;0;0}.

Boolean values, when multiplied, return their numerical equivalents. TRUE - 1 and FALSE is 0 (zero).

Here is why AND logic is created when we multiply boolean values, both values must be TRUE in order to return TRUE.

TRUE * TRUE = 1 (TRUE)

TRUE * FALSE = 0 (FALSE)

FALSE * FALSE = 0 (FALSE)

#### Step 4 - Evaluate XLOOKUP function

The XLOOKUP function search one column for a given value, and return a corresponding value in another column from the same row.

Function syntax: XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

XLOOKUP(1,(B3:B12=D14)*(C3:C12=D15),D3:D12)

returns "The New Firm".

## 2.2 XLOOKUP function with two conditions applied to two columns (OR logic)?

This example shows how to perform lookups in two different columns using two different lookup values respectively. The first record that meets at least one of two conditions is a match, in this example, row 3 is a match and the corresponding value in column D is returned.

Excel 365 formula in cell D17:

### Explaining formula

#### Step 1 - First condition

The equal sign is a logical operator, it lets you compare a value to another value in an Excel formula. The result is a boolean value, TRUE or FALSE.

You can use the equal sign to compare a value to a cell range of values as well.

D14=B3:B12

returns {TRUE; FALSE; FALSE; ... ; FALSE}

#### Step 2 - Second condition

D15=C3:C12

returns {FALSE; FALSE; FALSE; ... ; TRUE}.

#### Step 3 - Apply OR logic

The parentheses let you control the order of operation. We need to calculate the comparisons before we multiply the arrays.

(D14=B3:B12)+(D15=C3:C12)

returns {1; 0; 0; 0; 2; 0; 0; 0; 0; 1}.

The plus sign performs addition between two numbers and also boolean values.

TRUE + TRUE = 2 (TRUE)

TRUE + FALSE = 1 (TRUE)

FALSE + FALSE = 0 (FALSE)

Boolean values, when added, are converted to their numerical equivalents.

TRUE - All numbers except zero.

FALSE - 0 (Zero)

#### Step 4 - Check if numbers are larger than or equal to 1

The larger than sign is a logical operator that lets you compare numbers and also text values if needed. The result is a boolean value, TRUE or FALSE.

((D14=B3:B12)+(D15=C3:C12))>=1

#### Step 5 - Evaluate XLOOKUP function

The XLOOKUP function search one column for a given value, and return a corresponding value in another column from the same row.

Function syntax: XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

XLOOKUP(TRUE, ((D14=B3:B12)+(D15=C3:C12))>=1, D3:D12)

returns "Atlantic Corporation".

## 2.3 XLOOKUP - multiple conditions in one column (OR logic)?

This example demonstrates the XLOOKUP function using multiple conditions, however, it returns only a single value from the same row where any of the lookup values are found.

This example shows that the first condition is found before the second condition and the corresponding value on the same row is found in cell D5.

Excel 365 formula in cell D17:

### Explaining formula

#### Step 1 - Count conditions in each value

The COUNTIF function calculates the number of cells that is equal to a condition.

Function syntax: COUNTIF(range, criteria)

COUNTIF(D14:D15, B3:B12)

returns {0; 0; 1; 1; 0; 0; 1; 1; 0; 0}.

#### Step 2 - Lookup based on array

The XLOOKUP function search one column for a given value, and return a corresponding value in another column from the same row.

Function syntax: XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

XLOOKUP(1, COUNTIF(D14:D15, B3:B12), D3:D12)

returns "Omni Consumer Products".

## 2.4 Can we use XLOOKUP with multiple lookup values?

This example demonstrates the XLOOKUP function also using multiple conditions, however, it returns as many values as there are conditions as long as they match the lookup values..

This example shows the condition in cell D14 is found in cell B5 and the corresponding value in cell D5 is returned to cell D17. The second condition in cell D15 is found in cell B6 and the corresponding value in cell D6 is returned to cell D18.

Excel 365 dynamic formula in cell D17:

### Explaining formula

The XLOOKUP function lets you lookup multiple values in a single formula, the result is an Excel 365 dynamic array that spills values to cells below automatically.

#### Evaluate XLOOKUP function

XLOOKUP(D14:D15, B3:B12, D3:D12)

returns {"Omni Consumer Products"; "Galaxy Corp"}.

## 2.5 XLOOKUP across multiple columns?

This example performs a lookup across multiple columns using a single lookup value, a value from the first match on the same row is returned, in this example, cells D3:D12.

Excel 365 formula in cell D17:

### Explaining formula

#### Step 1 - First column B

You can use the equal sign to compare a value to a cell range of values as well.

B3:B12=D14

returns {FALSE; TRUE; FALSE; ... ; FALSE}.

#### Step 2 - Second column C

C3:C12=D14

returns {FALSE; FALSE; FALSE; ... ; FALSE}.

#### Step 3 - Apply OR logic

The plus sign adds numbers in an Excel formula, it also performs OR logic for boolean values and their numerical equivalents.

TRUE + TRUE = TRUE

TRUE + FALSE = TRUE

FALSE + FALSE = FALSE

OR logic means that at least one boolean value is TRUE in order to return TRUE.

TRUE - Any number except 0 (zero)

FALSE - 0 (zero)

The parentheses lets you control the order of operation, we need to compare the values before we add arrays.

(B3:B12=D14)+(C3:C12=D14)

returns {0;1;0;... ;0}.

#### Step 4 - Evaluate XLOOKUP function

XLOOKUP(1,(B3:B12=D14)+(C3:C12=D14),D3:D12)

returns "Uplink Corporation".

## 2.6 Can you concatenate XLOOKUP results?

You can concatenate results from the XLOOKUP function, this example demonstrates an XLOOKUP function that lookups two different values, and the results are concatenated using the TEXTJOIN function.

Excel 365 formula in cell D17:

### Explaining formula

#### Step 1 - Lookup two different values

XLOOKUP(D14:D15,B3:B12,D3:D12)

returns {"Omni Consumer Products"; "Galaxy Corp"}.

#### Step 2 - Join values

The TEXTJOIN function combines text strings from multiple cell ranges.

Function syntax: TEXTJOIN(delimiter, ignore_empty, text1, [text2], ...)

TEXTJOIN(", ",TRUE, XLOOKUP(D14:D15,B3:B12,D3:D12))

returns "Omni Consumer Products, Galaxy Corp".

## 2.7 How to use XLOOKUP with dates?

This example shows how to use a date range, Excel table, and a condition in the XLOOKUP function. The cell reference (structured reference) to the Excel Table doesn't change even if you add or delete rows in the table.

Excel 365 formula:

### Explaining formula

#### Step 1 - Find dates equal or larger than the start date specified in cell D15

The less than and larger than characters are logical operators, they return TRUE or FALSE if the condition is met or not.

Table35[Date]>=D15

returns {FALSE; TRUE; TRUE; ... ; TRUE}.

#### Step 2 - Find dates equal or larger than the end date specified in cell D16

Table35[Date]<=D16

returns {TRUE; TRUE; TRUE; ... ; FALSE}.

#### Step 3 - Find records matching condition specified in cell D14

D14=Table35[Item]

returns {TRUE; FALSE; FALSE; ... ; FALSE}.

#### Step 4 - Apply AND logic

The parentheses let you control the order of operation. We need to calculate the comparisons before we multiply the arrays.

(Table35[Date]>=D15)*(Table35[Date]<=D16)*(D14=Table35[Item])

The asterisk character lets you multiply boolean values.Â When multiplied boolean values return their numerical equivalents. TRUE - 1 and FALSE is 0 (zero).

TRUE * TRUE = 1 (TRUE)

TRUE * FALSE = 0 (FALSE)

FALSE * FALSE = 0 (FALSE)

Both values must be TRUE in order to return TRUE.

returns {0; 0; 0; 0; 1; 0; 0; 0; 0; 0}

#### Step 5 - Evaluate XLOOKUP function

XLOOKUP(1, (Table35[Date]>=D15)*(Table35[Date]<=D16)*(D14=Table35[Item]), Table35[Company Name])

returns "The New Firm".

## 2.8 What if I don't have the lookup column in the left-most column?

The XLOOKUP function lets you use any lookup column contrary to the VLOOKUP function that requires the leftmost column as the lookup column.

This example demonstrates a lookup column in column C, the leftmost column is column B in the data set.

Formula in cell D15:

### Evaluate XLOOKUP function

XLOOKUP(D14, C3:C12, D3:D12)

returns "Atlantic Corporation".

### Vlookup category

Question: Does anyone know how to do a VLOOKUPÂ of three columns to pull a single record? Table of Contents VLOOKUP […]

Have you ever tried to build a formula to calculate discounts based on price? The VLOOKUP function is much easier […]

### Excel categories

### 33 Responses to “How to use VLOOKUP/XLOOKUP with multiple conditions”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

Wow I have never thought of using the Table like that...... really potent stuff!

chrisham,

Thank you for commenting! You can use arrays in most excel functions.

I am having a problem getting vlookup to work when asking it to check two different tables based on what data is percent in specific cells. Basically I want it to check one table if a persons gender is male, and another table if the gender is female. Any idea how I can accomplish this? I would really appreciate any help I could get. Thank you very much.

Hi Oscar,

I want to sum up results of Vlookup

please help

For eg,

Product No in Column A and qty sold in Column B

I Will need to derive qty sold of each product. It's a huge data of 2000 odd product list

please suggest

Vicky,

Here is a post about pivot tables:

https://www.get-digital-help.com/2012/11/09/analyze-trends-using-pivot-tables/

You can also use formulas. How to extract a unique distinct list:

https://www.get-digital-help.com/how-to-extract-a-unique-list-and-the-duplicates-in-excel-from-one-column/

How to use the sumif function:

https://www.get-digital-help.com/sum-values-between-two-dates-with-criteria-in-excel/

Remove the date criteria.

Hi OScar

SUMIFS,has worked great for me, Thanks for your help. Its been completely Superb

Hi Oscar,

Just a general question, which one is better for huge lookups

Vlookup or Index + Match

can we use index + match instead of vlookup, even if we need to extract values from the right side columns

Thanks

Krishna

Krishna,

Yes, read this: https://exceluser.com/blog/1107/why-index-match-is-far-better-than-vlookup-or-hlookup-in-excel.html

Hi Oscar.. I'm struggling using a lookup formula for extracting values from a large table.. it's something like:

Fruit Market

Apple Walmart

Pear Sigo

Grapes Sigo

Cherry Walmart

Orange 7-eleven

The idea is just extract the fruits from Walmart in a new table but excluding the rest of the fruits.. What do you suggest??? Thanking you in advance for your help...

Jose,

Array formula in cell D2:

=INDEX($A$2:$B$6, SMALL(IF($B$2:$B$6=$D$1, MATCH(ROW($B$2:$B$6), ROW($B$2:$B$6)), ""), ROW(A1)),COLUMN(A1))

Read more:

How to return multiple values using vlookup

Dear Oscar,

I want to vlookup with 2 conditions.

I want to search for value by using two criteria. ex: vlookup with invoice number and serial number search for the discription in other sheet or other related information. Each invoice number has multiple serial numbers or items.Ex. invoice number 1 has 1to 5 items, I need search for all 5 items from database to the main sheet.

Please help

Simao Pereira,

Can you provide some data and the desired outcome?

Awesome formula:

=VLOOKUP(C2,IF(B8:B17=C3,A8:E17,""),3,FALSE)

Thanks for sharing this technique.

=VLOOKUP(C2,IF(B8:B17=C3,A8:E17,""),3,FALSE)

Did anyone check this formula ? I get "Value" error (a value used in this formula is of the wrong data type). Any ideas ? ...

Andrei,

It is an array formula.

Select a cell

Type the array formula

Press and hold Ctrl + Shift simultaneously

Press Enter

Release all keys

If you did it right you now have curly brackets before and after the formula, in the formula bar.

It works. I've never done this before. I just feel so silly sometimes - whenever I think I know Excel, something new appears that makes me look like a hairstylist. :(

Hi,

Perhaps you can help me with a similar formula.

I am trying to keep track of components for manufacturing purposes. I have one table where i keep my manufacturing data (product, quantity and date) each of my products require a unique valve and i want to have another table where i can look up the item and if it falls in a particular month indicate the total quantity.

My goal here is to be able to accurately forecast my valve needs.

I have attached an example. https://postimg.org/image/3uvet6l2f/

The incoming valve column i use for valve orders that i place. the cylinder production column is where i need the formula to match the item and time period and return the results.

Thank you very much!

Hi Oscar,

Please how do I handle this case...

An excel column has up to a thousand entries and each entry is to be looked up in another column. The aim is to find out if their is any entry among the up to one thousand entries which is in the other column or not. Since the number of entries to be looked up for is large, I want to avoid doing this one at a time.

Ray,

Use the match function to see if an entry exists in another column.

MATCH(A1,C1:C100000,0) If it returns a number it exists, an error it does not exist.

If we have a data like this in one excel sheet

y 10.94.44.185/

w 10.94.44.184/10.94.44.185/

y 10.94.44.181/10.94.44.182

w 10.94.44.184/10.94.44.185/10.94.44.186

I want Y & W = highest details in second column

Y=10.94.44.181/10.94.44.182

W=10.94.44.184/10.94.44.185/10.94.44.186

which formula can I apply, please let me know some one.

Hi I'm trying to do a vlookup from detail related to a person ID. However, the ID has two records. One record is "Completed" and another record is "Pending Update". How do I formulate it such that the vlookup will pick up the "Pending Update" line instead of the "Completed"

I have a vlookup table that retrieves an employee list.

What I need is when I select an employee from the lookup.

When I move to the next row I only want to be able to select an employee that has not been previously selected.

To add to the above I need the function to select multiple employees.

Hi,

I have a back dated product wise period wise amendments of rates and I want to vlookup the new rate against the product for a specific date in the past.

Oscar, I know this is an older thread, but I am trying to use a version of the VLOOKUP and two conditions (date range)formula, but my table is on another tab and instead of matching my Id's from tab1 to the Ids in table 1,(C2 in the actual formula), it's providing the actual value in my table matching the cell reference from tab 1. So it's giving me the ID in cell A129 instead of trying to find a match for that ID in the table.

I am not sure what I am doing wrong. Can you provide assistance?

Tasha

Can you upload a workbook, I have trouble understanding.

[…] Using multiple conditions in VLOOKUP […]

I HAVE BELOW CODE

id name amt

1 Bijankur-BB2 390

2 pkm 240

3 bajra 495

4 induce 535

ORDER is punch in like this 4 Unit Fodder Grass Bijankur-BB2 50 gm Rs. 345

how can i use vlookp & index function

Need Help: I have an file with Column B having entries and i need to match these with my entries in column A. However the column B may have multiple relevant values in column B. How do i do it? Also if i enter any values of column B it has to give me an output of the values i have in column A.

Sample:

S.No City Variable

1 a 123

2 b 111

3 b 124

4 a 145

5 c 167

6 d 192

7 e 122

8 a 111

9 a 109

10 e 110

Type City Here a

S.No City Variable

1 a 123

4 a 145

8 a 111

9 a 109

Hi Srikanth

I believe this article is what you are looking for:Extract multiple records based on a condition

Hi Oscar,

Thanks for the explanation and examples. It helped me in using the conditional within vlookup funtion.

Great help for new learners.

Good Day to you, I have a question.

I need a Vlookup or should it be sumif formulas for 2 sheets, base on two criteria on sheet2. First the date (A1)in sheet 2, then the Item code (B1)in sheet 2, to get the total amount at sheet1 for a certain item.

its kinda like your first graph here, first find the Item, then Region, to get the answer.

but my answer is quantity and need to add up.

hope to get some help from u.

Thanks you so much

Thank you for the examples. I needed a way to look up workers' compensation class code premium rates by state. I had a table of about 200 class codes, in each of 3 states. Being able to find a class code rate based on the state required this 2 column lookup. The IF inside of the VLOOKUP did the trick perfectly!