lookup_formulas¶
shortfx.fxExcel.lookup_formulas
¶
Excel Lookup and Reference Functions Module.
This module provides Excel-compatible lookup and reference functions for shortfx. Functions include: - ADDRESS: Build a cell reference string - CHOOSE, CHOOSECOLS, CHOOSEROWS: Selection functions - COLUMN, COLUMNS: Column number / count - DROP, TAKE: Array manipulation - EXPAND: Expand an array to specified dimensions - FILTER: Filter data by criteria - HLOOKUP, VLOOKUP, XLOOKUP: Lookup functions - HSTACK, VSTACK: Array stacking - INDEX: Index-based lookup - INDIRECT: Parse a cell-reference string - LOOKUP: Vector lookup - MATCH, XMATCH: Position matching - OFFSET: Return a sub-range from a 2-D array - ROW, ROWS: Row number / count - SORT, SORTBY: Sorting functions - TOCOL, TOROW: Array reshaping - TRANSPOSE: Transpose a 2-D array - TRIMRANGE: Trim blank edges from arrays - UNIQUE: Extract unique values - WRAPCOLS, WRAPROWS: Array wrapping
All functions follow Excel naming conventions and behavior.
Functions¶
ADDRESS(row_num: int, column_num: int, abs_num: int = 1, a1: bool = True, sheet_text: str = '') -> str
¶
Build a cell-reference string from row/column numbers.
Excel function: ADDRESS
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row_num
|
int
|
Row number (1-based). |
required |
column_num
|
int
|
Column number (1-based). |
required |
abs_num
|
int
|
Reference type (1=absolute, 2=abs row/rel col, 3=rel row/abs col, 4=relative). |
1
|
a1
|
bool
|
True for A1 style, False for R1C1 style. |
True
|
sheet_text
|
str
|
Optional sheet name prefix. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Cell reference string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If row_num or column_num < 1 or abs_num not in 1..4. |
Usage Example
ADDRESS(1, 1) '$A$1'
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
CHOOSE(index_num: int, *values: Any) -> Any
¶
Choose a value from a list of values based on index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_num
|
int
|
Index number (1-based) of the value to choose. |
required |
*values
|
Any
|
List of values to choose from. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Value at the specified index. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If index is out of range. |
Example
CHOOSE(2, "red", "blue", "green") 'blue' CHOOSE(1, 10, 20, 30) 10
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
CHOOSECOLS(array: List[List[Any]], *col_nums: int) -> List[List[Any]]
¶
Return specified columns from an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array from which to select columns. |
required |
*col_nums
|
int
|
Column numbers to select (1-based, negative from end). |
()
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Array with only the specified columns. |
Example
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] CHOOSECOLS(data, 1, 3) [[1, 3], [4, 6], [7, 9]]
Cost: O(r * c) where r=rows, c=selected columns
Source code in shortfx/fxExcel/lookup_formulas.py
CHOOSEROWS(array: List[List[Any]], *row_nums: int) -> List[List[Any]]
¶
Return specified rows from an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array from which to select rows. |
required |
*row_nums
|
int
|
Row numbers to select (1-based, negative from end). |
()
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Array with only the specified rows. |
Example
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] CHOOSEROWS(data, 1, 3) [[1, 2, 3], [7, 8, 9]]
Cost: O(r * c) where r=selected rows, c=columns
Source code in shortfx/fxExcel/lookup_formulas.py
COLUMN(reference: Optional[List[List[Any]]] = None, col_index: int = 1) -> int
¶
Return the column number of a reference.
Excel function: COLUMN
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Optional[List[List[Any]]]
|
Ignored in shortfx (kept for API compat). |
None
|
col_index
|
int
|
The 1-based column number to return. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Column number. |
Usage Example
COLUMN(col_index=3) 3
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
COLUMNS(array: List[List[Any]]) -> int
¶
Return the number of columns in an array or reference.
Excel function: COLUMNS
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
2-D list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of columns. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If array is not a list. |
Usage Example
COLUMNS([[1,2,3],[4,5,6]]) 3
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
DROP(array: List[List[Any]], rows: int = 0, columns: int = 0) -> List[List[Any]]
¶
Exclude a specified number of rows or columns from start or end of array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to process. |
required |
rows
|
int
|
Number of rows to drop (positive from start, negative from end). |
0
|
columns
|
int
|
Number of columns to drop (positive from start, negative from end). |
0
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Array with specified rows/columns removed. |
Example
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] DROP(data, 1, 1) [[5, 6], [8, 9]]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
EXPAND(array: List[List[Any]], rows: Optional[int] = None, columns: Optional[int] = None, pad_with: Any = '') -> List[List[Any]]
¶
Expand an array to the specified dimensions, padding with a value.
Excel function: EXPAND
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
2-D list to expand. |
required |
rows
|
Optional[int]
|
Target number of rows (default: keep current). |
None
|
columns
|
Optional[int]
|
Target number of columns (default: keep current). |
None
|
pad_with
|
Any
|
Value to fill in new cells. |
''
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Expanded array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If target dimensions are smaller than the input. |
Usage Example
EXPAND([[1,2],[3,4]], 3, 4, 0) [[1, 2, 0, 0], [3, 4, 0, 0], [0, 0, 0, 0]]
Cost: O(rows * columns)
Source code in shortfx/fxExcel/lookup_formulas.py
FILTER(array: List[List[Any]], include: List[bool], if_empty: Any = None) -> Union[List[List[Any]], Any]
¶
Filter a range of data based on criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to filter. |
required |
include
|
List[bool]
|
Boolean array indicating which rows to include. |
required |
if_empty
|
Any
|
Value to return if no rows match. |
None
|
Returns:
| Type | Description |
|---|---|
Union[List[List[Any]], Any]
|
Union[List[List[Any]], Any]: Filtered array or if_empty value. |
Example
data = [[1, "A"], [2, "B"], [3, "C"]] FILTER(data, [True, False, True]) [[1, 'A'], [3, 'C']]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
HLOOKUP(lookup_value: Any, table_array: List[List[Any]], row_index_num: int, range_lookup: bool = True) -> Any
¶
Search in the top row of an array and return value from specified row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_value
|
Any
|
Value to search for in first row. |
required |
table_array
|
List[List[Any]]
|
Array to search. |
required |
row_index_num
|
int
|
Row number to return value from (1-based). |
required |
range_lookup
|
bool
|
True for approximate match, False for exact match. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Value from the specified row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value not found (exact match) or index out of range. |
Example
table = [["A", "B", "C"], [1, 2, 3], [10, 20, 30]] HLOOKUP("B", table, 2) 2
Cost: O(c) where c=columns
Source code in shortfx/fxExcel/lookup_formulas.py
HSTACK(*arrays: List[List[Any]]) -> List[List[Any]]
¶
Append arrays horizontally and in sequence to return a larger array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*arrays
|
List[List[Any]]
|
Arrays to stack horizontally. |
()
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Horizontally stacked array. |
Example
a1 = [[1], [2], [3]] a2 = [[4], [5], [6]] HSTACK(a1, a2) [[1, 4], [2, 5], [3, 6]]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
INDEX(array: List[List[Any]], row_num: int = 0, column_num: int = 0) -> Union[Any, List[Any]]
¶
Use an index to choose a value from a reference or array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to index. |
required |
row_num
|
int
|
Row number (1-based, 0 for all rows). |
0
|
column_num
|
int
|
Column number (1-based, 0 for all columns). |
0
|
Returns:
| Type | Description |
|---|---|
Union[Any, List[Any]]
|
Union[Any, List[Any]]: Value at position or entire row/column. |
Example
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] INDEX(data, 2, 3) 6
Cost: O(1) for single value, O(n) for row/column
Source code in shortfx/fxExcel/lookup_formulas.py
INDIRECT(ref_text: str, a1: bool = True) -> Tuple[int, int]
¶
Parse a cell-reference string into (row, column) indices.
Excel function: INDIRECT
In a spreadsheet engine INDIRECT resolves a live reference; in shortfx it parses the text and returns the 1-based (row, column) tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref_text
|
str
|
Cell reference string (e.g. "A1", "$B$3", "R2C3"). |
required |
a1
|
bool
|
True for A1 style, False for R1C1 style. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple[int, int]
|
Tuple[int, int]: (row_number, column_number) both 1-based. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ref_text cannot be parsed. |
Usage Example
INDIRECT("B3") (3, 2)
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
LOOKUP(lookup_value: Any, lookup_vector: List[Any], result_vector: Optional[List[Any]] = None) -> Any
¶
Look up values in a vector or array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_value
|
Any
|
Value to search for. |
required |
lookup_vector
|
List[Any]
|
Sorted array to search. |
required |
result_vector
|
Optional[List[Any]]
|
Optional array of values to return. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Corresponding value. |
Example
LOOKUP(5, [1, 3, 5, 7], ["A", "B", "C", "D"]) 'C'
Cost: O(log n)
Source code in shortfx/fxExcel/lookup_formulas.py
MATCH(lookup_value: Any, lookup_array: List[Any], match_type: int = 1) -> int
¶
Return the relative position of an item in an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_value
|
Any
|
Value to search for. |
required |
lookup_array
|
List[Any]
|
Array to search. |
required |
match_type
|
int
|
1=largest value <=, 0=exact match, -1=smallest value >=. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Position (1-based) of the match. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no match found. |
Example
MATCH("B", ["A", "B", "C"]) 2
Cost: O(n) for linear search, O(log n) for sorted
Source code in shortfx/fxExcel/lookup_formulas.py
OFFSET(reference: List[List[Any]], rows: int, cols: int, height: Optional[int] = None, width: Optional[int] = None) -> List[List[Any]]
¶
Return a sub-range from a 2-D array offset from a starting cell.
Excel function: OFFSET
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
List[List[Any]]
|
2-D list used as the source range. |
required |
rows
|
int
|
Row offset from top-left of reference. |
required |
cols
|
int
|
Column offset from top-left of reference. |
required |
height
|
Optional[int]
|
Number of rows to return (default: same as reference). |
None
|
width
|
Optional[int]
|
Number of columns to return (default: same as reference). |
None
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: The extracted sub-range. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the resulting range falls outside the array. |
Usage Example
OFFSET([[1,2],[3,4],[5,6]], 1, 0, 2, 2) [[3, 4], [5, 6]]
Cost: O(height * width)
Source code in shortfx/fxExcel/lookup_formulas.py
ROW(reference: Optional[List[List[Any]]] = None, row_index: int = 1) -> int
¶
Return the row number of a reference.
Excel function: ROW
In shortfx, row_index simulates the starting row of the range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Optional[List[List[Any]]]
|
Ignored in shortfx (kept for API compat). |
None
|
row_index
|
int
|
The 1-based row number to return. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Row number. |
Usage Example
ROW(row_index=5) 5
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
ROWS(array: List[List[Any]]) -> int
¶
Return the number of rows in an array or reference.
Excel function: ROWS
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
2-D list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of rows. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If array is not a list. |
Usage Example
ROWS([[1,2],[3,4],[5,6]]) 3
Cost: O(1)
Source code in shortfx/fxExcel/lookup_formulas.py
SORT(array: List[List[Any]], sort_index: int = 1, sort_order: int = 1, by_col: bool = False) -> List[List[Any]]
¶
Sort the contents of a range or array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to sort. |
required |
sort_index
|
int
|
Row or column index to sort by (1-based). |
1
|
sort_order
|
int
|
1 for ascending, -1 for descending. |
1
|
by_col
|
bool
|
False to sort by row, True to sort by column. |
False
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Sorted array. |
Example
data = [[3, "C"], [1, "A"], [2, "B"]] SORT(data) [[1, 'A'], [2, 'B'], [3, 'C']]
Cost: O(n log n)
Source code in shortfx/fxExcel/lookup_formulas.py
SORTBY(array: List[List[Any]], by_array1: List[Any], sort_order1: int = 1, *args) -> List[List[Any]]
¶
Sort the contents of a range based on corresponding values in other ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to sort. |
required |
by_array1
|
List[Any]
|
First array to sort by. |
required |
sort_order1
|
int
|
1 for ascending, -1 for descending. |
1
|
*args
|
Additional by_array, sort_order pairs. |
()
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Sorted array. |
Example
data = [[1, "A"], [3, "C"], [2, "B"]] by = [3, 1, 2] SORTBY(data, by) [[3, 'C'], [2, 'B'], [1, 'A']]
Cost: O(n log n)
Source code in shortfx/fxExcel/lookup_formulas.py
TAKE(array: List[List[Any]], rows: int = None, columns: int = None) -> List[List[Any]]
¶
Return a specified number of contiguous rows or columns from start or end of array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to process. |
required |
rows
|
int
|
Number of rows to take (positive from start, negative from end). |
None
|
columns
|
int
|
Number of columns to take (positive from start, negative from end). |
None
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Array with specified rows/columns. |
Example
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] TAKE(data, 2, 2) [[1, 2], [4, 5]]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
TOCOL(array: List[List[Any]], ignore: int = 0, scan_by_column: bool = False) -> List[List[Any]]
¶
Return the array as a single column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to transform. |
required |
ignore
|
int
|
0=keep all, 1=ignore blanks, 2=ignore errors, 3=ignore both. |
0
|
scan_by_column
|
bool
|
False for row-wise, True for column-wise. |
False
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Single column array. |
Example
data = [[1, 2], [3, 4]] TOCOL(data) [[1], [2], [3], [4]]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
TOROW(array: List[List[Any]], ignore: int = 0, scan_by_column: bool = False) -> List[List[Any]]
¶
Return the array as a single row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to transform. |
required |
ignore
|
int
|
0=keep all, 1=ignore blanks, 2=ignore errors, 3=ignore both. |
0
|
scan_by_column
|
bool
|
False for row-wise, True for column-wise. |
False
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Single row array. |
Example
data = [[1, 2], [3, 4]] TOROW(data) [[1, 2, 3, 4]]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
TRANSPOSE(array: List[List[Any]]) -> List[List[Any]]
¶
Transpose a 2-D array (swap rows and columns).
Excel function: TRANSPOSE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
2-D list to transpose. |
required |
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Transposed array. |
Usage Example
TRANSPOSE([[1,2],[3,4]]) [[1, 3], [2, 4]]
Cost: O(rows * cols)
Source code in shortfx/fxExcel/lookup_formulas.py
TRIMRANGE(array: List[List[Any]]) -> List[List[Any]]
¶
Trim blank rows and columns from the edges of a range or array.
Examines from the edges of a range or array until it finds a cell (or value) that is not blank, then excludes those blank rows or columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[List[Any]]
|
The array to trim. |
required |
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Array with blank rows/columns removed from edges. |
Example
data = [[None, None, None], [None, 1, 2], [None, 3, 4], [None, None, None]] TRIMRANGE(data) [[1, 2], [3, 4]]
Cost: O(r * c) where r=rows, c=columns
Source code in shortfx/fxExcel/lookup_formulas.py
UNIQUE(array: List[Any], by_col: bool = False, exactly_once: bool = False) -> List[Any]
¶
Return a list of unique values from a list or range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
List[Any]
|
The array to process. |
required |
by_col
|
bool
|
False for unique rows, True for unique columns. |
False
|
exactly_once
|
bool
|
False for all unique, True for values appearing once. |
False
|
Returns:
| Type | Description |
|---|---|
List[Any]
|
List[Any]: Array of unique values. |
Example
UNIQUE([1, 2, 2, 3, 1, 4]) [1, 2, 3, 4]
Cost: O(n log n)
Source code in shortfx/fxExcel/lookup_formulas.py
VLOOKUP(lookup_value: Any, table_array: List[List[Any]], col_index_num: int, range_lookup: bool = True) -> Any
¶
Search in the first column of an array and return value from specified column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_value
|
Any
|
Value to search for in first column. |
required |
table_array
|
List[List[Any]]
|
Array to search. |
required |
col_index_num
|
int
|
Column number to return value from (1-based). |
required |
range_lookup
|
bool
|
True for approximate match, False for exact match. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Value from the specified column. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value not found (exact match) or index out of range. |
Example
table = [["A", 1, 10], ["B", 2, 20], ["C", 3, 30]] VLOOKUP("B", table, 2) 2
Cost: O(r) where r=rows
Source code in shortfx/fxExcel/lookup_formulas.py
VSTACK(*arrays: List[List[Any]]) -> List[List[Any]]
¶
Append arrays vertically and in sequence to return a larger array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*arrays
|
List[List[Any]]
|
Arrays to stack vertically. |
()
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Vertically stacked array. |
Example
a1 = [[1, 2, 3]] a2 = [[4, 5, 6]] VSTACK(a1, a2) [[1, 2, 3], [4, 5, 6]]
Cost: O(r * c)
Source code in shortfx/fxExcel/lookup_formulas.py
WRAPCOLS(vector: List[Any], wrap_count: int, pad_with: Any = None) -> List[List[Any]]
¶
Wrap the provided row or column of values by columns after specified number of elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
List[Any]
|
The vector to wrap. |
required |
wrap_count
|
int
|
Number of values per column. |
required |
pad_with
|
Any
|
Value to pad incomplete columns. |
None
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Wrapped array. |
Example
WRAPCOLS([1, 2, 3, 4, 5, 6], 2) [[1, 3, 5], [2, 4, 6]]
Cost: O(n)
Source code in shortfx/fxExcel/lookup_formulas.py
WRAPROWS(vector: List[Any], wrap_count: int, pad_with: Any = None) -> List[List[Any]]
¶
Wrap the provided row or column of values by rows after specified number of elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
List[Any]
|
The vector to wrap. |
required |
wrap_count
|
int
|
Number of values per row. |
required |
pad_with
|
Any
|
Value to pad incomplete rows. |
None
|
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List[List[Any]]: Wrapped array. |
Example
WRAPROWS([1, 2, 3, 4, 5, 6], 3) [[1, 2, 3], [4, 5, 6]]
Cost: O(n)
Source code in shortfx/fxExcel/lookup_formulas.py
XLOOKUP(lookup_value: Any, lookup_array: List[Any], return_array: List[Any], if_not_found: Any = '#N/A', match_mode: int = 0, search_mode: int = 1) -> Any
¶
Search a range or array and return corresponding item from second range/array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_value
|
Any
|
Value to search for. |
required |
lookup_array
|
List[Any]
|
Array to search. |
required |
return_array
|
List[Any]
|
Array of values to return. |
required |
if_not_found
|
Any
|
Value to return if no match found. |
'#N/A'
|
match_mode
|
int
|
0=exact, -1=exact or next smaller, 1=exact or next larger, 2=wildcard. |
0
|
search_mode
|
int
|
1=first to last, -1=last to first, 2=binary ascending, -2=binary descending. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Corresponding value from return_array. |
Example
XLOOKUP("B", ["A", "B", "C"], [10, 20, 30]) 20
Cost: O(n) for linear search, O(log n) for binary
Source code in shortfx/fxExcel/lookup_formulas.py
XMATCH(lookup_value: Any, lookup_array: List[Any], match_mode: int = 0, search_mode: int = 1) -> int
¶
Return the relative position of an item in an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_value
|
Any
|
Value to search for. |
required |
lookup_array
|
List[Any]
|
Array to search. |
required |
match_mode
|
int
|
0=exact, -1=exact or next smaller, 1=exact or next larger, 2=wildcard. |
0
|
search_mode
|
int
|
1=first to last, -1=last to first, 2=binary ascending, -2=binary descending. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Position (1-based) of the match. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no match found. |
Example
XMATCH("B", ["A", "B", "C"]) 2
Cost: O(n) for linear, O(log n) for binary