Skip to content

VLOOKUP and HLOOKUP return the first match instead of the last one when RangeLookup = TRUE #1072

Closed

Description

@sequba

Description

From ODFF:

If RangeLookup is omitted or TRUE or not 0, the first row of DataSource is assumed to be sorted in ascending order, with smaller numbers before larger ones [...] The lookup will try to match an entry of value Lookup. If none is found the largest entry less than Lookup is taken as a match. From a sequence of identical values ≤ Lookup the last entry is taken.

Steps to reproduce

These tests fail:

    it('VLOOKUP should return the last matching value if RangeLookup = TRUE', () => {
      const engine =HyperFormula.buildFromArray([
        ['1', 'a'],
        ['2', 'b'],
        ['2', 'c'],
        ['2', 'd'],
        ['2', 'e'],
        ['=VLOOKUP(2, A1:B5, 2, TRUE())'],
      ])

      expect(engine.getCellValue(adr('A6'))).toEqual('e')
    })

    it('HLOOKUP should return the last matching value if RangeLookup = TRUE', () => {
      const engine = HyperFormula.buildFromArray([
        ['1', '2', '2', '2', '5'],
        ['a', 'b', 'c', 'd', 'e'],
        ['=HLOOKUP(2, A1:E2, 2, TRUE())'],
      ])

      expect(engine.getCellValue(adr('A3'))).toEqual('d')
    })

Links

Related: #1063

Activity

  1. added
    Bug
    on Oct 3, 2022
  2. self-assigned this
    on Oct 3, 2022
  3. added
    Function
    and removed on Oct 3, 2022
  4. sequba commented on Nov 17, 2022

    @sequba
    ContributorAuthor

    Closing as released in HyperFormula 2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugFunctionImpact: High

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions