atoti.measure module

class atoti.measure.Measure(_name, _data_type, _cube, _java_api, _folder=None, _formatter=None, _visible=True, _description=None)

A measure is a mostly-numeric data value, computed on demand for aggregation purposes.

Measures can be compared to other objects, such as a literal value, a Level, or another measure. The returned measure represents the outcome of the comparison and this measure can be used as a condition. If the measure’s value is None when evaluating a condition, the returned value will be False.

Example

>>> df = pd.DataFrame(
...     columns=["Id", "Value", "Threshold"],
...     data=[
...         (0, 1.0, 5.0),
...         (1, 2.0, None),
...         (2, 3.0, 3.0),
...         (3, 4.0, None),
...         (4, 5.0, 1.0),
...     ],
... )
>>> table = session.read_pandas(df, keys=["Id"], table_name="Measure example")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> m["Condition"] = m["Value.SUM"] > m["Threshold.SUM"]
>>> cube.query(m["Condition"], levels=[l["Id"]])
   Condition
Id
0      False
1      False
2      False
3      False
4       True
property data_type: atoti.type.DataType

Type of the measure members.

Return type

DataType

property description: Optional[str]

Description of the measure.

Return type

Optional[str]

property folder: Optional[str]

Folder of the measure.

It can be changed by assigning a new value to the property (None to clear it).

Return type

Optional[str]

property formatter: Optional[str]

Formatter of the measure.

It can be changed by assigning a new value to the property (None to clear it).

Examples

  • DOUBLE[0.00%] for percentages

  • DOUBLE[#,###] to remove decimals

  • DOUBLE[$#,##0.00] for dollars

  • DATE[yyyy-MM-dd HH:mm:ss] for datetimes

The spec for the pattern between the DATE or DOUBLE’s brackets is the one from Microsoft Analysis Services. The formatter only impacts how the measure is displayed, derived measures will still be computed from unformatted value. To round a measure, use atoti.math.round() instead.

atoti provides an extra formatter for array measures: ARRAY['|';1:3] where | is the separator used to join the elements of the 1:3 slice.

Return type

Optional[str]

property name: str

Name of the measure.

Return type

str

property visible: bool

Whether the measure is visible or not.

It can be toggled by assigning a new boolean value to the property.

Return type

bool