atoti.agg.sum_product module#

atoti.agg.sum_product(*factors, scope=None)#

Return a measure equal to the sum product aggregation of the passed factors across the specified scope.

Parameters
  • factors (Union[Column, Operation, MeasureDescription, MeasureConvertible]) – Column, Measure or Level to do the sum product of.

  • scope (Optional[Scope]) – The scope of the aggregation. When None is specified, the natural aggregation scope is used: it contains all the data in the cube which coordinates match the ones of the currently evaluated member.

Example

>>> from datetime import date
>>> df = pd.DataFrame(
...     columns=["Date", "Category", "Price", "Quantity", "Array"],
...     data=[
...         (date(2020, 1, 1), "TV", 300.0, 5, [10.0, 15.0]),
...         (date(2020, 1, 2), "TV", 200.0, 1, [5.0, 15.0]),
...         (date(2020, 1, 1), "Computer", 900.0, 2, [2.0, 3.0]),
...         (date(2020, 1, 2), "Computer", 800.0, 3, [10.0, 20.0]),
...         (date(2020, 1, 1), "TV", 500.0, 2, [3.0, 10.0]),
...     ],
... )
>>> table = session.read_pandas(
...     df,
...     table_name="Date",
... )
>>> table.head()
        Date  Category  Price  Quantity         Array
0 2020-01-01        TV  300.0         5  [10.0, 15.0]
1 2020-01-02        TV  200.0         1   [5.0, 15.0]
2 2020-01-01  Computer  900.0         2    [2.0, 3.0]
3 2020-01-02  Computer  800.0         3  [10.0, 20.0]
4 2020-01-01        TV  500.0         2   [3.0, 10.0]
>>> cube = session.create_cube(table)
>>> h, l, m = cube.hierarchies, cube.levels, cube.measures
>>> m["turnover"] = tt.agg.sum_product(table["Price"], table["Quantity"])
>>> cube.query(m["turnover"], levels=[l["Category"]])
          turnover
Category
Computer  4,200.00
TV        2,700.00
>>> m["array sum product"] = tt.agg.sum_product(table["Price"], table["Array"])
>>> cube.query(m["array sum product"])
               array sum product
0  doubleVector[2]{15300.0, ...}
Return type

MeasureDescription