HLOOKUP
Looks up a value in the first row of a table and returns a value from another row.
HLOOKUP searches horizontally and returns the matching column's value from row_index_num.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
lookup_value | any | Required | — |
table_array | any (range) | Required | — |
row_index_num | number | Required | — |
range_lookup | logical | Optional | true |
Remarks
row_index_numis 1-based and must be within the table height.range_lookupdefaults toTRUE, matching Excel and LibreOffice.- When
range_lookup=TRUE, approximate match logic is used against the first row. - In exact mode, a blank candidate never matches. A blank lookup value matches a real numeric zero, but not blank, text, or boolean candidates.
- Numeric
range_lookupvalues use logical coercion: zero is exact and nonzero is approximate. - A matched empty target cell is materialized as numeric
0.
Error cases
- Approximate matching assumes the first row is sorted ascending. Unsorted data is detected and returns
#N/Arather than a silently wrong column, matching LibreOffice Calc (#283). - If the lookup value is not found, returns
#N/A. - If
row_index_numis invalid, returns#REF!(or#VALUE!if non-numeric).
Examples
Match a header exactly and retrieve the second row.
Formula =HLOOKUP("Q2",{"Q1","Q2","Q3";10,20,30},2,FALSE)
Expected result 20
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Use an approximate lookup in the sorted first row.
Formula =HLOOKUP(25,{10,20,30;"Low","Mid","High"},2,TRUE)
Expected result Mid
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Retrieve the value from the first row itself.
Formula =HLOOKUP("Q1",{"Q1","Q2";10,20},1,FALSE)
Expected result Q1
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A missing exact-match key returns an error.
Formula =HLOOKUP("Q4",{"Q1","Q2","Q3";10,20,30},2,FALSE)
Expected result #N/A
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Exact match across header row
Formula =HLOOKUP("Feb",A1:B2,2,FALSE)
| A | B | |
|---|---|---|
| 1 | "Jan" | "Feb" |
| 2 | 120 | 150 |
Expected result 150
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Approximate threshold lookup
Formula =HLOOKUP(72,A1:C2,2,TRUE)
| A | B | C | |
|---|---|---|---|
| 1 | 0 | 50 | 80 |
| 2 | "F" | "C" | "A" |
Expected result C
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
Does HLOOKUP default to exact or approximate matching?
It defaults to approximate matching because range_lookup defaults to TRUE; pass FALSE or 0 for exact matching.
How are invalid row_index_num values reported?
If row_index_num is outside table height HLOOKUP returns #REF!; if it is non-numeric it returns #VALUE!.