From 69c7ebf24b8661281f569acade28b903426c26a5 Mon Sep 17 00:00:00 2001 From: Rushmore75 Date: Fri, 23 Jan 2026 13:35:50 -0700 Subject: [PATCH] make xlookup function like excel --- README.md | 2 +- src/app/logic/calc.rs | 2 +- src/app/logic/ctx.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cf8da3e..ee8cbfb 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ These commands operate on selections. | - | - | - | - | | `avg` | ≥ 1 | Numeric | Returns the average of the arguments | | `sum` | ≥ 1 | Numbers | Returns the sum of the arguments | -| `xlookup` | 3 | Range, Number/String, Range | Searches for the number/string in the first range, returning the item at the same index in the second range | +| `xlookup` | 3 | Number/String, Range, Range | Searches for the number/string in the first range, returning the item at the same index in the second range | | `min` | ≥ 1 | Numeric | Returns the minimum of the arguments | | `max` | ≥ 1 | Numeric | Returns the maximum of the arguments | | `len` | 1 | String/Tuple | Returns the character length of a string, or the amount of elements in a tuple (not recursively) | diff --git a/src/app/logic/calc.rs b/src/app/logic/calc.rs index f430b64..60849ca 100644 --- a/src/app/logic/calc.rs +++ b/src/app/logic/calc.rs @@ -788,7 +788,7 @@ fn xlookup_function() { grid.set_cell("A1", "Sarah".to_string()); grid.set_cell("C0", 31.); grid.set_cell("C1", 41.); - grid.set_cell("B0", "=xlookup(A:A,\"Bobby\",C:C)".to_string()); + grid.set_cell("B0", "=xlookup(\"Bobby\",A:A,C:C)".to_string()); let cell = grid.get_cell("B0").as_ref().expect("Just set the cell"); let res = grid.evaluate(&cell.to_string()); assert!(res.is_ok()); diff --git a/src/app/logic/ctx.rs b/src/app/logic/ctx.rs index 30f6e3a..00be8cd 100644 --- a/src/app/logic/ctx.rs +++ b/src/app/logic/ctx.rs @@ -104,13 +104,13 @@ impl<'a> CallbackContext<'a> { functions.insert( "xlookup".to_string(), Function::new(|arg| { - let expected = vec![ValueType::Tuple, ValueType::String, ValueType::Tuple]; + let expected = vec![ValueType::String, ValueType::Tuple, ValueType::Tuple]; if arg.is_tuple() { let args = arg.as_tuple()?; if args.len() == 3 { - let lookup_array = &args[0]; - let lookup_value = &args[1]; + let lookup_value = &args[0]; + let lookup_array = &args[1]; let return_array = &args[2]; if lookup_array.is_tuple() && return_array.is_tuple() {