Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOOKUP can only find exact match #997

Closed
stanim opened this issue Aug 18, 2021 · 0 comments · Fixed by #1001
Closed

LOOKUP can only find exact match #997

stanim opened this issue Aug 18, 2021 · 0 comments · Fixed by #1001
Projects

Comments

@stanim
Copy link
Contributor

stanim commented Aug 18, 2021

Description

The LOOKUP function only returns a result if it can find an exact match in lookup vector, but does not support:

If the LOOKUP function can't find the lookup_value, the function matches the largest value in lookup_vector that is less than or equal to lookup_value.

If lookup_value is smaller than the smallest value in lookup_vector, LOOKUP returns the #N/A error value.

Important: The values in array must be placed in ascending order: ..., -2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE; otherwise, LOOKUP might not return the correct value. Uppercase and lowercase text are equivalent.

According to the official Microsoft Excel documentation: https://support.microsoft.com/en-us/office/lookup-function-446d94af-663b-451d-8251-369d5e3864cb

Steps to reproduce the issue:

  1. Add a test which looks for the nearest value:
	cellData := [][]interface{}{
		{1, 4, nil, "Month", "Team", "Sales"},
		{2, 5, nil, "Jan", "North 1", 36693},
		{3, nil, nil, "Jan", "North 2", 22100},
		{0, nil, nil, "Jan", "South 1", 53321},
		{nil, nil, nil, "Jan", "South 2", 34440},
		{nil, nil, nil, "Feb", "North 1", 29889},
		{nil, nil, nil, "Feb", "North 2", 50090},
		{nil, nil, nil, "Feb", "South 1", 32080},
		{nil, nil, nil, "Feb", "South 2", 45500},
	}
	mathCalc := map[string]string{
                ...
		"=LOOKUP(F3+1,F3:F4,F3:F4)":    "22100",
  1. Run go test.

Describe the results you received:

> go test
--- FAIL: TestCalcCellValue (7.88s)
    calc_test.go:1218: 
        	Error Trace:	calc_test.go:1218
        	Error:      	Received unexpected error:
        	            	LOOKUP no result found
        	Test:       	TestCalcCellValue
        	Messages:   	=LOOKUP(F3+1,F3:F4,F3:F4)
    calc_test.go:1219: 
        	Error Trace:	calc_test.go:1219
        	Error:      	Not equal: 
        	            	expected: "22100"
        	            	actual  : ""
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-22100
        	            	+
        	Test:       	TestCalcCellValue
        	Messages:   	=LOOKUP(F3+1,F3:F4,F3:F4)

Describe the results you expected:

I expected the test to pass.

Output of go version:

go version go1.16.7 linux/amd64

Excelize version or commit ID:

> git log
commit a55f354eb3d0c6c1b9a543ff8ff98227aa6063a6 (HEAD -> lookup, origin/master, origin/HEAD, master)
Author: xuri <[email protected]>
Date:   Tue Aug 17 00:01:44 2021 +0800

    This closes #989, closes #990
    
    New API: `SetRowStyle` support for set style for the rows
    Update documentation for the `GetRows`, `SetCellStyle` and `SetColStyle`

Environment details (OS, Microsoft Excel™ version, physical, etc.):

  • OS: Archlinux 5.13.10-arch1-1
  • WPS Spreadsheets (version wps-office 11.1.0.10702-1)
  • LibreCalc (version libreoffice-fresh 7.1.5-2)

I'll try to make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v2.5.0
Bugfix
Development

Successfully merging a pull request may close this issue.

1 participant