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

Add XLOOKUP without support for non standard match_mode and search_mode - and returning values/arrays instead of ranges #1414

Merged
merged 9 commits into from
Dec 5, 2024

Conversation

selimyoussry
Copy link
Contributor

@selimyoussry selimyoussry commented Jun 15, 2024

Context

Per this discussion it seems like XLOOKUP is useful to a bunch of people. It is to for me at the very least :) and so I am happy to contribute to its implementation!

How did you test your changes?

I have tested the XLOOKUP implementation against the examples from Microsoft's official doc

  • Example 1: should find value in simple column range
  • Example 2: should find row range in table
  • Example 2 transposed: should find column range in table (official example 2, transposed). This makes sure both column and row search work.
  • Example 3: should find use if_not_found argument if not found
  • Example 4: current limitation of this implementation, the approximate match and non standard search are not supported. I added these limitations to the documentation. Hence, this example is not tested against.
  • Example 5: nested xlookup function to perform both a vertical and horizontal match (official example 5)
  • Example 6: two nested xlookup + sum (official example 6). I wrote the code but then realized that (based on my shallow understanding of Hyperformula, please correct me if I am wrong), Hyperformula does not support functions returning ranges, only functions returning values.

Types of changes

  • Breaking change (a fix or a feature because of which an existing functionality doesn't work as expected anymore)
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues:

Checklist:

  • I have reviewed the guidelines about Contributing to HyperFormula and I confirm that my code follows the code style of this project.
  • I have signed the Contributor License Agreement.
  • My change is compliant with the OpenDocument standard. This does not apply as XLOOKUP is not part of this standard
  • My change is compatible with Microsoft Excel.
  • My change is compatible with Google Sheets. Should be if the XLOOKUP implementation in Sheets is the same as Excel
  • I described my changes in the CHANGELOG.md file. That feels like it's up to you guys to see if that's releasable :)
  • My changes require a documentation update.
  • My changes require a migration guide.

@selimyoussry selimyoussry changed the title Add XLOOKUP Add XLOOKUP (WIP) Jun 15, 2024
@selimyoussry selimyoussry changed the title Add XLOOKUP (WIP) Add XLOOKUP without support for non standard match_mode and search_mode - and returning values/arrays instead of ranges Jun 16, 2024
@selimyoussry selimyoussry marked this pull request as ready for review June 16, 2024 18:04
@AMBudnik
Copy link
Contributor

Thank you for signing the CLA and sharing the pull request.

@AMBudnik AMBudnik added the CLA signed Required for PR label Jun 18, 2024
Copy link
Contributor

@sequba sequba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very solid implementation. Thanks a lot, @selimyoussry. We appreciate that you invested your time to contribute to the HyperFormula.

It requires polishing and probably some of the limitations you described can be addressed to make the function more robust, but it's a good starting point and certainly the right direction to go about implementing the XLOOKUP function.

@@ -227,6 +227,7 @@ Total number of functions: **{{ $page.functionsCount }}**
| ROW | Returns row number of a given reference or formula reference if argument not provided. | ROW([Reference]) |
| ROWS | Returns the number of rows in the given reference. | ROWS(Array) |
| VLOOKUP | Searches vertically with reference to adjacent cells to the right. | VLOOKUP(Search_Criterion, Array, Index, Sort_Order) |
| XLOOKUP | The XLOOKUP function searches a range or an array, and then returns the item corresponding to the first match it finds. If no match exists, then XLOOKUP can return the closest (approximate) match. Current limitations: only default match_mode and search_mode are supported, a range of value is returned, not a range, so having XLOOKUP(...):XLOOKUP(...) will not work. | XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode]) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand why you put it here, but the current convention in HyperFormula is to describe the limitations of the built-in functions in pages https://hyperformula.handsontable.com/guide/list-of-differences.html (difference in results from other spreadsheets) and https://hyperformula.handsontable.com/guide/known-limitations.html#nuances-of-the-implemented-functions (general limitations).

@@ -232,6 +232,7 @@ const dictionary: RawTranslationPackage = {
WEEKNUM: 'HAFTASAY',
WORKDAY: 'İŞGÜNÜ',
'WORKDAY.INTL': 'İŞGÜNÜ.ULUSL',
XLOOKUP: 'ÇAPRAZARA',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing the translations. We really appreciate it.

* @param ast
* @param state
*/
public xlookup(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very solid implementation 💪

@sequba sequba mentioned this pull request Nov 13, 2024
@sequba sequba changed the base branch from develop to feature/issue-1458 December 5, 2024 13:09
@sequba sequba merged commit 1f9d091 into handsontable:feature/issue-1458 Dec 5, 2024
2 checks passed
@sequba
Copy link
Contributor

sequba commented Dec 5, 2024

Merging this PR into a local branch to fine-tune the implementation. Thank you, @selimyoussry, for the contribution.

@AMBudnik
Copy link
Contributor

Thank you again for your input, @selimyoussry, and for spending your time improving HyperFormula. I'm glad to see the new function added in HF v3. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA signed Required for PR Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants