database_formulas¶
shortfx.fxExcel.database_formulas
¶
Excel Database Functions Module.
This module provides Excel-compatible database functions that operate on structured data (list of dictionaries). Functions include: - DCOUNT, DCOUNTA: Count functions - DAVERAGE, DSUM: Aggregate functions - DMAX, DMIN: Statistical functions - DSTDEV, DSTDEVP, DVAR, DVARP: Variance and standard deviation - DPRODUCT: Product calculation - DGET: Single record extraction
All functions follow Excel naming conventions and behavior.
Functions¶
DAVERAGE(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> float
¶
Calculate average of database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to average. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Average value, 0 if no values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] DAVERAGE(db, 'Value', None) 20.0
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DCOUNT(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> int
¶
Count cells containing numbers in a database field that match criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to count. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Count of numeric values matching criteria. |
Example
db = [{'Name': 'Alice', 'Age': 30}, {'Name': 'Bob', 'Age': 25}] DCOUNT(db, 'Age', None) 2
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DCOUNTA(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> int
¶
Count non-empty cells in a database field that match criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to count. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Count of non-empty values matching criteria. |
Example
db = [{'Name': 'Alice', 'Age': 30}, {'Name': 'Bob', 'Age': None}] DCOUNTA(db, 'Age', None) 1
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DGET(database: List[Dict[str, Any]], field: str, criteria: Dict[str, Any]) -> Any
¶
Extract a single value from a database field that matches criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to extract. |
required |
criteria
|
Dict[str, Any]
|
Dictionary with filtering criteria. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Field value from the matching record, None if not found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If multiple records match criteria (Excel behavior). |
Example
db = [{'Name': 'Alice', 'Age': 30}, {'Name': 'Bob', 'Age': 25}] DGET(db, 'Age', {'Name': 'Alice'}) 30
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DMAX(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> Optional[Union[int, float]]
¶
Return maximum value from database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to analyze. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Union[int, float]]
|
Union[int, float, None]: Maximum value, None if no values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] DMAX(db, 'Value', None) 30
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DMIN(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> Optional[Union[int, float]]
¶
Return minimum value from database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to analyze. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Union[int, float]]
|
Union[int, float, None]: Minimum value, None if no values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] DMIN(db, 'Value', None) 10
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DPRODUCT(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> Union[int, float]
¶
Multiply values from database field that match criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to multiply. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Type | Description |
|---|---|
Union[int, float]
|
Union[int, float]: Product of values, 0 if no values. |
Example
db = [{'Value': 2}, {'Value': 3}, {'Value': 4}] DPRODUCT(db, 'Value', None) 24
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DSTDEV(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> float
¶
Calculate sample standard deviation of database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to analyze. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Sample standard deviation, 0 if less than 2 values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] DSTDEV(db, 'Value', None) 10.0
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DSTDEVP(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> float
¶
Calculate population standard deviation of database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to analyze. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Population standard deviation, 0 if no values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] round(DSTDEVP(db, 'Value', None), 2) 8.16
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DSUM(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> Union[int, float]
¶
Sum values from database field that match criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to sum. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Type | Description |
|---|---|
Union[int, float]
|
Union[int, float]: Sum of values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] DSUM(db, 'Value', None) 60
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DVAR(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> float
¶
Calculate sample variance of database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to analyze. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Sample variance, 0 if less than 2 values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] DVAR(db, 'Value', None) 100.0
Cost: O(n) where n is the number of records.
Source code in shortfx/fxExcel/database_formulas.py
DVARP(database: List[Dict[str, Any]], field: str, criteria: Optional[Dict[str, Any]] = None) -> float
¶
Calculate population variance of database field values matching criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
List[Dict[str, Any]]
|
List of dictionaries representing database records. |
required |
field
|
str
|
Field name to analyze. |
required |
criteria
|
Optional[Dict[str, Any]]
|
Optional dictionary with filtering criteria. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Population variance, 0 if no values. |
Example
db = [{'Value': 10}, {'Value': 20}, {'Value': 30}] round(DVARP(db, 'Value', None), 2) 66.67
Cost: O(n) where n is the number of records.