atoti.agg.single_value()#

atoti.agg.single_value(operand: Column, /) MeasureDescription#
atoti.agg.single_value(operand: NonConstantMeasureConvertible, /, *, scope: CumulativeScope | SiblingsScope | OriginScope) MeasureDescription

Return a measure equal to the value aggregation of the operand across the specified scope.

If the value is the same for all members of the level the operand is being aggregated on, it will be propagated to the next level.

None values are ignored: they will not prevent the propagation.

Parameters:
  • operand – The measure or table column to aggregate.

  • scope – The aggregation scope.

Example

>>> df = pd.DataFrame(
...     columns=["Continent", "Country", "City", "Price"],
...     data=[
...         ("Europe", "France", "Paris", 200.0),
...         ("Europe", "France", "Lyon", 200.0),
...         ("Europe", "UK", "London", 200.0),
...         ("Europe", "UK", "Manchester", 150.0),
...         ("Europe", "France", "Bordeaux", None),
...     ],
... )
>>> table = session.read_pandas(
...     df, table_name="City price table", keys=["Continent", "Country", "City"]
... )
>>> cube = session.create_cube(table)
>>> h, l, m = cube.hierarchies, cube.levels, cube.measures
>>> geography_level_names = ["Continent", "Country", "City"]
>>> h["Geography"] = [table[name] for name in geography_level_names]
>>> for name in geography_level_names:
...     del l[name, name]
>>> m["Price.VALUE"] = tt.agg.single_value(table["Price"])
>>> cube.query(
...     m["Price.VALUE"],
...     levels=[l["City"]],
...     include_empty_rows=True,
...     include_totals=True,
... )
                             Price.VALUE
Continent Country City
Total
Europe
          France                  200.00
                  Bordeaux
                  Lyon            200.00
                  Paris           200.00
          UK
                  London          200.00
                  Manchester      150.00
  • The City level is the most granular level so the members have the same value as in the input dataframe (including None for Bordeaux).

  • All the cities in France have the same price or None so the value is propagated to the Country level. The values in the UK cities are different so Price.VALUE is None.

  • The cities in Europe have different values so the Price.VALUE is None at the Continent level.