# Reverse two-way lookups

This article demonstrates a few different formulas that extract values from the table column header names and the right-most column.

The image above shows the formula in cell C9, it extracts values from row two and column B if they intersect with a range of values specified in cell C7 and C8.

Example, value 0.4 is in cell E3, cells E2 and B3 are on the same column and same row respectively. The values 53 and 31 are extracted and shown in cell C9.

#### Table of Contents

The Excel 2016 formula lets you concatenate all values in one cell and it works only in excel 2016 because of the TEXTJOIN function. You only need one formula and it is small and easy to understand.

The version that works with all Excel versions lets you put values in a cell each however the formulas are a little bit more complicated.

## 1. Reverse two-way lookups in a cross-reference table [Excel 2016]

table

Row 2 contains variable and Column B contains another variable

The combination of 32 with 51 gives me 0.9 or cell D4

I need to report which 2 and B combinations give me values between 0.4 and 0.5. In this case, it would be 31-53 and 32-50.

I could rearrange this to be in 3 columns with the results on the last column and use something like below (The equation does not represent the example I gave.)

IFERROR(INDEX(array, SMALL(IF((min=data), ROW($B$2:$B$10)-1), ROW(A3)), COLUMN(A3)), " ")

This works but my excel table would have too many rows and the initial data set comes the other way so it would take some time to convert it. The original matrix is more compact.

I am trying to convert this equation but I am having trouble matching it to an array instead to just one column.

The following array formula returns multiple values from a cross-reference table if they meet specific criteria.

Array formula in cell H3:

If you prefer having the values in a cell each instead of concatenated values in one cell, go to this part of this article.

### 1.1 How to build an array formula

If you did above steps correctly excel automatically adds a beginning and ending curly bracket to the formula, like this:

Don't enter these characters yourself.

### 1.2 Explaining array formula in cell G3

Note, the TEXTJOIN function works only in Excel 2016. Use this formula if you have an earlier version of Excel.

#### Step 1 - Check which values are larger than the condition in cell H1

The less than sign and equal sign are logical operators and can be combined, the result is a boolean value True or False.

$C$3:$E$5>=$H$1

becomes

{0.1, 0.7, 0.4; 0.5, 0.9, 0.8; 0.8, 0.6, 0.6}>=0.4

and returns

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

#### Step 2 - Check which values are smaller than the condition in cell H2

$C$3:$E$5<=$H$2

becomes

{0.1, 0.7, 0.4; 0.5, 0.9, 0.8; 0.8, 0.6, 0.6}<=0.5

and returns

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

#### Step 3 - Both conditions must be TRUE (AND-logic)

($C$3:$E$5>=$H$1)*($C$3:$E$5<=$H$2)

becomes

{FALSE, TRUE, TRUE; TRUE, TRUE, TRUE; TRUE, TRUE, TRUE} * {TRUE,FALSE,TRUE; TRUE,FALSE,FALSE; FALSE,FALSE,FALSE}

and returns {0, 0, 1; 1, 0, 0; 0, 0, 0}.

#### Step 4 - Extract corresponding values from B3:B5 and C2:E2

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

IF(*logical_test*, [*value_if_true*], [*value_if_false*])

IF(($C$3:$E$5>=$H$1)*($C$3:$E$5<=$H$2), $B$3:$B$5&"-"&$C$2:$E$2,"")

becomes

IF({0,0,1;1,0,0;0,0,0}, $B$3:$B$5&"-"&$C$2:$E$2,"")

becomes

IF({0,0,1;1,0,0;0,0,0}, {"31-50","31-51","31-53";"32-50","32-51","32-53";"33-50","33-51","33-53"},"")

and returns {"","","31-53";"32-50","","";"","",""},

#### Step 5 - Concatenate values using TEXTJOIN function

The TEXTJOIN function allows you to combine text strings from multiple cell ranges and also use delimiting characters if you want.

TEXTJOIN(*delimiter*, *ignore_empty*, *text1*, *[text2]*, ...)

TEXTJOIN(",",TRUE,{"","","31-53";"32-50","","";"","",""})

returns

"31-53. 32-50" in cell H3.

Link to two-way lookups in an index table:

Looking up data in a cross reference table

#### Get excel *.xlsx file

Reverse two-way lookup in a cross reference table.xlsx

## 2. Reverse two-way lookups in a cross-reference table

This formula is for excel versions that don't have the TEXTJOIN function or if you prefer having the values in a cell each instead of concatenated values in one cell.

Array formula in cell G7:

Array formula in cell H7:

Array formula in cell I7:

### 2.1 Explaining formula in cell G7

#### Step 1 - Check which values are larger than the condition in cell H1

The less than sign and equal sign are logical operators and can be combined, the result is a boolean value True or False.

$C$3:$E$5>=$H$1

becomes

{0.45, 0.7, 0.4; 0.5, 0.9, 0.47; 0.8, 0.6, 0.42}>=0.4

and returns

{TRUE, TRUE, TRUE;TRUE, TRUE, TRUE;TRUE, TRUE, TRUE}.

#### Step 2 - Check which values are smaller than the condition in cell H2

$C$3:$E$5<=$H$2

becomes

{0.45, 0.7, 0.4; 0.5, 0.9, 0.47; 0.8, 0.6, 0.42}<=0.5

and returns

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

#### Step 3 - Both conditions must be TRUE (AND-logic)

($C$3:$E$5>=$H$1)*($C$3:$E$5<=$H$2)

becomes

{TRUE, TRUE, TRUE;TRUE, TRUE, TRUE;TRUE, TRUE, TRUE} * {TRUE, FALSE, TRUE; TRUE, FALSE, TRUE; FALSE, FALSE, TRUE}

and returns {1, 0, 1;1, 0, 1;0, 0, 1}.

#### Step 4 - Create a sequence from 1 to n

The ROW function returns row numbers based on a cell reference.

ROW($B$3:$B$5)

returns {3; 4; 5}.

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

MATCH(lookup_value, lookup_array, [match_type])

MATCH(ROW($B$3:$B$5), ROW($B$3:$B$5))

becomes

MATCH({3; 4; 5}, {3; 4; 5})

and returns {1; 2; 3}.

#### Step 5 - Return corresponding row number if True

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

IF(*logical_test*, [*value_if_true*], [*value_if_false*])

IF(($C$3:$E$5<=$H$2)*($C$3:$E$5>=$H$1)*(G7=$B$3:$B$5) ,MATCH(COLUMN($C$2:$E$2), COLUMN($C$2:$E$2)), "")

becomes

IF({1, 0, 1;1, 0, 1;0, 0, 1}, {1; 2; 3}, "")

and returns {1,"", 1; 2, "", 2; "", "", 3}.

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

The SMALL function returns the k-th smallest value from a group of numbers.

SMALL(*array*, *k*)

SMALL(IF(($C$3:$E$5<=$H$2)*($C$3:$E$5>=$H$1), MATCH(ROW($B$3:$B$5), ROW($B$3:$B$5)), ""), ROW(A1))

becomes

SMALL({1,"", 1; 2, "", 2; "", "", 3}, ROW(A1))

becomes

SMALL({1,"", 1; 2, "", 2; "", "", 3}, 1)

and returns 1.

#### Step 7 - Return value based on a row number

The INDEX function returns a value from a cell range, you specify which value based on a row and column number.

INDEX(array, [row_num], [column_num])

INDEX($B$3:$B$5, SMALL(IF(($C$3:$E$5<=$H$2)*($C$3:$E$5>=$H$1), MATCH(ROW($B$3:$B$5), ROW($B$3:$B$5)), ""), ROW(A1)))

becomes

INDEX($B$3:$B$5, 1)

amd returns 31.

### 2.2 Explaining formula in cell H7

### 2.3 Explaining formula in cell I7

#### Get excel *.xlsx file

Reverse-two-way-lookup-in-a-cross-reference-tablev3.xlsx

## 3. Reverse two-way lookup in a cross-reference table

The following array formulas return a single value from a cross-reference table.

Array formula in cell E15:

Array formula in cell E16:

### 3.1 Explaining array formula in cell E15

#### Step 1 - Check what values in cell range equals the value in E14 and return the smallest row

MIN(IF(B3:K12=E14, MATCH(ROW(B3:K12), ROW(B3:K12)), ""))

returns 5.

#### Step 2 - Return corresponding header value

=INDEX($A$3:$A$12, 5)

returns H.

Geoff asks: Hi Oscar, I have a cross reference table we use for shift scheduling. The x-axis is comprised of […]

How to perform a two-dimensional lookup

Question: How would I go about looking up data in a cross-reference table. I have the header row (i.e. 24) […]

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

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

Two-dimensional lookup using two tables

The following formula performs a two-way lookup in two different tables. Weekly Blog EMAIL Email Welcome! I am Oscar and […]

Get date ranges from a schedule

The above picture shows you two formulas that extract names (column B) and date ranges (column C and D) based […]

### 5 Responses to “Reverse two-way lookups”

### 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

[…] https://www.get-digital-help.com/2017/05/16/reverse-two-way-lookup-in-a-cross-reference-table/ […]

Hi Oscar,

Thank you very much.

Is there a way to report each combination with its corresponding results so in the example provided you would see

Column J Column K Column L

31 53 0.4

32 50 0.5

or

Column J Column K

31-53 0.4

32-50 0.5

Thanks Again.

Polar

(P.S Sorry this is a repost from the old thread. Just making sure I am not confusing things).

Polar,

Yes, it is possible. Read this.

Thank you!

[…] Tip! Read this post to do Reverse two-way lookup in a cross reference table. […]