atoti.Measure.formatter#

property Measure.formatter: str | None#

Formatter of the measure.

Note

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.

Example

>>> df = pd.DataFrame(
...     columns=["Product", "Price", "Quantity"],
...     data=[
...         ("phone", 559.99, 2),
...         ("headset", 79.99, 4),
...         ("watch", 249.99, 3),
...     ],
... )
>>> table = session.read_pandas(
...     df, keys=["Product"], table_name="Formatter example"
... )
>>> cube = session.create_cube(table)
>>> h, l, m = cube.hierarchies, cube.levels, cube.measures
>>> m["contributors.COUNT"].formatter
'INT[#,###]'
>>> m["contributors.COUNT"].formatter = "INT[count: #,###]"
>>> m["contributors.COUNT"].formatter
'INT[count: #,###]'
>>> m["Price.SUM"].formatter
'DOUBLE[#,###.00]'
>>> m["Price.SUM"].formatter = "DOUBLE[$#,##0.00]"  # Add $ symbol
>>> m["Ratio of sales"] = m["Price.SUM"] / tt.total(
...     m["Price.SUM"], h["Product"]
... )
>>> m["Ratio of sales"].formatter
'DOUBLE[#,###.00]'
>>> m["Ratio of sales"].formatter = "DOUBLE[0.00%]"  # Percentage
>>> m["Turnover in dollars"] = tt.agg.sum(
...     table["Price"] * table["Quantity"],
... )
>>> m["Turnover in dollars"].formatter
'DOUBLE[#,###.00]'
>>> m["Turnover in dollars"].formatter = "DOUBLE[#,###]"  # Without decimals
>>> cube.query(
...     m["contributors.COUNT"],
...     m["Price.SUM"],
...     m["Ratio of sales"],
...     m["Turnover in dollars"],
...     levels=[l["Product"]],
... )
        contributors.COUNT Price.SUM Ratio of sales Turnover in dollars
Product
headset           count: 1    $79.99          8.99%                 320
phone             count: 1   $559.99         62.92%               1,120
watch             count: 1   $249.99         28.09%                 750

The spec for the pattern between the DATE or DOUBLE’s brackets is the one from Microsoft Analysis Services.

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