Formulas

A Formula is a typed expression in a small modelling language modelled loosely on Microsoft Excel. Formulas are used by CalculatedField and Calculation to compute values from other fields and named values.

Build expressions with Python operators or with the helper functions in daitum_model.formulas:

import daitum_model.formulas as formulas
from daitum_model.formula import CONST

total = products["price"] * products["quantity"]            # Formula
is_expensive = products["price"] > CONST(100)               # Formula
summary = formulas.SUM(products["price"])                   # Formula

The Formula Class

class Formula(data_type, formula_string)[source]

Bases: Buildable, Operand

Represents a formula used in calculations or data processing.

data_type

The type of data that the formula returns.

Type:

DataType | ObjectDataType

formula_string

The Excel formula as a string.

Type:

str

to_data_type()[source]

Retrieves the data type of the formula.

Returns:

The data type associated with the formula.

Return type:

BaseDataType

to_string()[source]

Converts the formula expression to its string representation.

Returns:

The string representation of the formula expression.

Return type:

str

Built-in Formula Functions

The daitum_model.formulas submodule provides every built-in formula function.