XMATCH INDEX Approximate Lookup: Fast Even with 1 Million Rows (Sorting and Binary Search)

Build Fast Approximate Lookups with XMATCH + INDEX, Even for 1 Million Rows (Sorting and Binary Search)

The XMATCH INDEX approximate lookup combination is fast and transparent, even with large datasets. Use XMATCH binary search to identify the boundary index accurately, then retrieve the value with INDEX to eliminate VLOOKUP’s weaknesses.

Quick Fix — 6 Steps to Fix “Slow” or “Incorrect” Results

  1. Confirm that the lookup column is sorted in ascending order.
  2. Choose -1 for the lower bound and 1 for the upper bound.
  3. Use a separate INDEX(XMATCH()) design.
  4. Lock ranges with Excel tables or absolute references.
  5. Snap to buckets with FLOOR.MATH/CEILING.MATH.
  6. Set a duplicate-boundary policy and apply search_mode.

Why XMATCH + INDEX?

Binary Search-Based match_mode

=XMATCH(value, lookup_range, -1)  // exact match or next smaller (≤)
=XMATCH(value, lookup_range,  1)  // exact match or next larger (≥)

Benefits of a Separate Design

Because INDEX uses an independent return range, it remains stable when columns move. Separating the XMATCH result into a helper column also makes testing easier.

Approximate Lookup Patterns

Lower-Bound Lookup

=INDEX($B$2:$B$6, XMATCH(E2, $A$2:$A$6, -1))

Upper-Bound Lookup

=INDEX($B$2:$B$6, XMATCH(E2, $A$2:$A$6, 1))

Duplicate Boundary Priority

=INDEX($B$2:$B$6, XMATCH(E2, $A$2:$A$6, -1, -1))

Performance Design for 1 Million Rows

  • Guarantee sorting: standardize number and date formats, and use Excel tables.
  • Minimize ranges, cache with helper columns, and eliminate repeated calculations with spills.
  • Reduce file size by saving as .xlsb.

Practical Example 1 — Score to Grade

Minimum ScoreGrade
0D
60C
70B
80A
90A+

=INDEX($B$2:$B$6, XMATCH(E2, $A$2:$A$6, -1))

Boundary snap: =INDEX($B$2:$B$6, XMATCH(FLOOR.MATH(E2,1), $A$2:$A$6, -1))

Practical Example 2 — Usage to Unit Price (Tiered Pricing)

Minimum UsageUnit Price (KRW)
0100
10090
30080
50070

Unit price lookup: =INDEX($B$2:$B$5, XMATCH(G2, $A$2:$A$5, -1))

Tiered total: After calculating usage for each tier, use =SUMPRODUCT(usage_range_by_tier, unit_price_range)

Alternatives, Considerations, and Checklist

  • INDEX+XMATCH is easier to debug than an all-in-one XLOOKUP formula.
  • Handle exceptions with bucket snapping and virtual lower or upper bounds.
  • [ ] Sorting guaranteed
  • [ ] Data types standardized
  • [ ] Intent for -1/1 specified
  • [ ] Duplicate policy and search direction set
  • [ ] Bucket snapping applied
  • [ ] Out-of-range exceptions handled

Conclusion & Related Articles


Official documentation: XMATCH Function, INDEX Function

Leave a Reply

Your email address will not be published. Required fields are marked *