1

I'm trying to avoid the redundancy of calculating the same index as many times as there are records, so should I pre-calculate the index with MATCH in a hidden cell above my table?

It is also worth noting that while my tables are not going to be massive, they are not going to be small either. Probably there are going to be about 6 tables each with one or two VLOOKUPS (full column) with a total count of records in the hundreds.

More precisely, I'm going to create a set of tables in Excel and I'm going to be emulating the goodies of a proper relational database using the VLOOKUP function to get a value of a related table, but I will make use of MATCH function to get the the index of the column I want by it's header. The following is the actual formula I will use:

=VLOOKUP([@ForeignKey],RelatedTable,MATCH(RelatedTable[[#Headers],[ItemName]],RelatedTable[#Headers],0),FALSE)
'Broken down by parameters
VLOOKUP(
  Lookup_value  := [@ForeignKey]
  Table_array   := RelatedTable
  Col_index_num := 'Return of MATCH
      MATCH(
        Lookup_value := RelatedTable[[#Headers],[ItemName]]
        Lookup_array := RelatedTable[#Headers]
        Match_type   := 0 'Exact Match
  Range_lookup  := FALSE 'Exact Match

EDIT:

The first table is the one with the primary key. The last two are either of the two examples I'm referring to.

Table_Products
╔════╦════════╦═══════════════╦═══════════╗
║    ║   A    ║       B       ║     C     ║
╠════╬════════╬═══════════════╬═══════════╣
║  1 ║ ItemID ║ ItemName      ║ ItemPrice ║
╠════╬════════╬═══════════════╬═══════════╣
║  2 ║      1 ║ Stylus        ║ $   25.00 ║
╠════╬════════╬═══════════════╬═══════════╣
║  3 ║      2 ║ Mech Keyboard ║ $  120.00 ║
╠════╬════════╬═══════════════╬═══════════╣
║  4 ║      3 ║ Monitor       ║ $  750.00 ║
╚════╩════════╩═══════════════╩═══════════╝

Table_Transactions

EITHER LIKE THIS
╔════╦════════╦════════╦═════╦═══════════════════════╗
║    ║   A    ║   B    ║  C  ║           D           ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  1 ║ CustID ║ ItemID ║ Qty ║ ItemName              ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  2 ║    101 ║      3 ║   1 ║ VLOOKUP(,,Match(,,),) ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  3 ║    102 ║      3 ║   2 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  4 ║    103 ║      3 ║   1 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  5 ║    104 ║      2 ║   3 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  6 ║    105 ║      1 ║   8 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  7 ║    106 ║      2 ║   2 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  8 ║    107 ║      2 ║   1 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║  9 ║    108 ║      2 ║   2 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║ 10 ║    109 ║      1 ║   4 ║          ...          ║
╠════╬════════╬════════╬═════╬═══════════════════════╣
║ 11 ║    110 ║      2 ║  16 ║          ...          ║
╚════╩════════╩════════╩═════╩═══════════════════════╝

OR LIKE THIS
(D1 cell is NOT part of the table)

╔════╦════════╦════════╦═════╦═════════════════╗
║    ║   A    ║   B    ║  C  ║        D        ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  1 ║        ║        ║     ║ Match(,,)       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  2 ║ CustID ║ ItemID ║ Qty ║ ItemName        ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  3 ║    101 ║      3 ║   1 ║ VLOOKUP(,,D$1,) ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  4 ║    102 ║      3 ║   2 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  5 ║    103 ║      3 ║   1 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  6 ║    104 ║      2 ║   3 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  7 ║    105 ║      1 ║   8 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  8 ║    106 ║      2 ║   2 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║  9 ║    107 ║      2 ║   1 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║ 10 ║    108 ║      2 ║   2 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║ 11 ║    109 ║      1 ║   4 ║       ...       ║
╠════╬════════╬════════╬═════╬═════════════════╣
║ 12 ║    110 ║      2 ║  16 ║       ...       ║
╚════╩════════╩════════╩═════╩═════════════════╝

7
  • Not sure what you are trying to achieve. Why wouldn't you do index/match vs. vlookup/match?
    – user218076
    Commented Jun 22, 2018 at 3:37
  • Because I don't know if it is bad practice to have an index laying outside of the table itself vs the table being completely self-contained.
    – David
    Commented Jun 22, 2018 at 3:55
  • Could you please post some sample data along with the output, will help us to solve the issue. Seems you are trying Vlookup(,,, Match(,,,,)) write? Commented Jun 22, 2018 at 7:23
  • @Rajesh S Sorry it took me a while to reply. Now there is an example with the two formats I'm talking about. Also, I'm asking from the perspective of an Excel user with no professional or formal background. I basically want to know if the latter example is not acceptable formally.
    – David
    Commented Jun 24, 2018 at 1:19
  • I usually use a cell in a hidden row to store the column number to be used with VLOOKUP. I must admit, I don't know if it is necessary. It's possible that if Excel sees that the same MATCH function is being many times, it calls the function once and saves the result to be used for all the other calls.
    – Blackwood
    Commented Jun 24, 2018 at 2:39

1 Answer 1

1

I would write in D2, =index(Table_Products'$B:$B,(match($B2,Table_Products'$A:$A,0)) You can also do a 2 way match if you want to change which column to return instead of hard coding the item name column (Column B). I can modify the answer if you need that.

I use this daily on sheets with 1000's of lookups on multible tables and don't notice any performance issues. In general, Index/Match is better than Vlookup, since vlookup needs to process the entire range.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .