atoti.agg module¶

atoti.agg.
count_distinct
(measure, *, scope=None)¶ Return a measure equal to the distinct count of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
long
(measure, *, scope=None)¶ Return a measure equal to the sum of the positive values of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
max
(measure, *, scope=None)¶ Return a measure equal to the maximum of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
max_member
(measure, level)¶ Return a measure equal to the member maximizing the passed measure on the given level.
When multiple members maximize the passed measure, the first one (according to the comparator of the given level) is returned.
Example
Considering this dataset:
Continent
City
Price
Europe
Paris
200.0
Europe
Berlin
150.0
Europe
London
240.0
North America
New York
270.0
And this measure:
m["City with max price"] = atoti.agg.max_member(m["Price"], lvl["City"])
Then, at the given level, the measure is equal to the current member of the City level:
cube.query(m["Price"], m["City with max price"], levels=lvl["City"])
City
Price
City with max price
Paris
200.0
Paris
Berlin
150.0
Berlin
London
240.0
London
New York
270.0
New York
At a level above it, the measure is equal to the city of each continent with the maximum price:
cube.query(m["City with min price"], levels=lvl["Continent"])
Continent
City with max price
Europe
London
North America
New York
At the top level, the measure is equal to the city with the maxium price across all continents:
cube.query(m["City with max price"])
City with max Price
New York
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure to maximize.level (
Level
) – The level on which the maximizing member is searched for.
 Return type

atoti.agg.
mean
(measure, *, scope=None)¶ Return a measure equal to the mean of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
median
(measure, *, scope=None)¶ Return a measure equal to the median of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
min
(measure, *, scope=None)¶ Return a measure equal to the minimum of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
min_member
(measure, level)¶ Return a measure equal to the member minimizing the passed measure on the given level.
When multiple members maximize the passed measure, the first one (according to the comparator of the given level) is returned.
Example
Considering this dataset:
Continent
City
Price
Europe
Paris
200.0
Europe
Berlin
150.0
Europe
London
240.0
North America
New York
270.0
And this measure:
m["City with min price"] = atoti.agg.min_member(m["Price"], lvl["City"])
Then, at the given level, the measure is equal to the current member of the City level:
cube.query(m["Price"], m["City with min price"], levels=lvl["City"])
City
Price
City with min price
Paris
200.0
Paris
Berlin
150.0
Berlin
London
240.0
London
New York
270.0
New York
At a level above it, the measure is equal to the city of each continent with the minimum price:
cube.query(m["City with min price"], levels=lvl["Continent"])
Continent
City with min price
Europe
Berlin
North America
New York
At the top level, the measure is equal to the city with the minium price across all continents:
cube.query(m["City with min price"])
City with min Price
Berlin
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure to minimize.level (
Level
) – The level on which the minimizing member is searched for.

atoti.agg.
prod
(measure, *, scope=None)¶ Return a measure equal to the product of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
quantile
(measure, q, *, mode='inc', interpolation='linear', scope=None)¶ Return a measure equal to the requested quantile of the passed measure across the specified scope.
Here is how to obtain the same behavior as these standard quantile calculation methods:
R1:
mode="centered"
andinterpolation="lower"
R2:
mode="centered"
andinterpolation="midpoint"
R3:
mode="simple"
andinterpolation="nearest"
R4:
mode="simple"
andinterpolation="linear"
R5:
mode="centered"
andinterpolation="linear"
R6 (similar to Excel’s
PERCENTILE.EXC
):mode="exc"
andinterpolation="linear"
R7 (similar to Excel’s
PERCENTILE.INC
):mode="inc"
andinterpolation="linear"
R8 and R9 are not supported
The formulae given for the calculation of the quantile index assume a 1based indexing system.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure to get the quantile of.q (
Union
[float
,Measure
]) – The quantile to take. Must be between0
and1
. For instance,0.95
is the 95th percentile and0.5
is the median.mode (
Literal
[‘simple’, ‘centered’, ‘inc’, ‘exc’]) –The method used to calculate the index of the quantile. Available options are, when searching for the q quantile of a vector
X
:simple
:len(X) * q
centered
:len(X) * q + 0.5
exc
:(len(X) + 1) * q
inc
:(len(X)  1) * q + 1
interpolation (
Literal
[‘linear’, ‘higher’, ‘lower’, ‘nearest’, ‘midpoint’]) –If the quantile index is not an integer, the interpolation decides what value is returned. The different options are, considering a quantile index
k
withi < k < j
for a sorted vectorX
:linear
:v = X[i] + (X[j]  X[i]) * (k  i)
lowest
:v = X[i]
highest
:v = X[j]
nearest
:v = X[i]
orv = X[j]
depending on which ofi
orj
is closest tok
midpoint
:v = (X[i] + X[j]) / 2
scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
short
(measure, *, scope=None)¶ Return a measure equal to the sum of the negative values of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
square_sum
(measure, *, scope=None)¶ Return a measure equal to the sum of the square of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
std
(measure, *, mode='sample', scope=None)¶ Return a measure equal to the standard deviation of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure to get the standard deviation of.mode (
Literal
[‘sample’, ‘population’]) –One of the supported modes:
The
sample
standard deviation, similar to Excel’sSTDEV.S
, is \(\sqrt{\frac{\sum_{i=0}^{n} (X_i  m)^{2}}{n  1}}\) wherem
is the sample mean andn
the size of the sample. Use this mode if the data represents a sample of the population.The
population
standard deviation, similar to Excel’sSTDEV.P
is \(\sqrt{\frac{\sum_{i=0}^{n}(X_i  m)^{2}}{n}}\) wherem
is the mean of theXi
elements andn
the size of the population. Use this mode if the data represents the entire population.
scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
sum
(measure, *, scope=None)¶ Return a measure equal to the sum of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure or store column to aggregate.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
sum_product
(*factors, scope=None)¶ Return a measure equal to the sum product aggregation of the passed factors across the specified scope.
Example
Considering this dataset with, for each day and product, the sold amount and the product price:
Date
Product ID
Category
Price
Amount
Array
20200101
001
TV
300.0
5.0
[10,15]
20200102
001
TV
200.0
1.0
[5,15]
20200101
002
Computer
900.0
2.0
[2,3]
20200102
002
Computer
800.0
3.0
[10,20]
20200101
003
TV
500.0
2.0
[3,10]
To compute the turnover:
m["turnover"] = atoti.agg.sum_product(store["Price"], store["Amount"])
To compute the turnover per category:
cube.query(m["turnover"], levels=["Category"])
It returns:
Category
turnover
TV
2700
Computer
4200
Sum product is also optimized for operations on vectors:
m["array sum product"] = atoti.agg.sum_product(store["Amount"], store["Array"])
cube.query(m[“array sum product”]) return [95.0, 176.0]
 Parameters
factors (
Union
[Measure
,MeasureConvertible
]) – Column, Measure or Level to do the sum product of.scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type

atoti.agg.
var
(measure, *, mode='sample', scope=None)¶ Return a measure equal to the variance of the passed measure across the specified scope.
 Parameters
measure (
Union
[Measure
,MeasureConvertible
]) – The measure to get the variance of.mode (
Literal
[‘sample’, ‘population’]) –One of the supported modes:
The
sample
variance, similar to Excel’sVAR.S
, is \(\frac{\sum_{i=0}^{n} (X_i  m)^{2}}{n  1}\) wherem
is the sample mean andn
the size of the sample. Use this mode if the data represents a sample of the population.The
population
variance, similar to Excel’sVAR.P
is \(\frac{\sum_{i=0}^{n}(X_i  m)^{2}}{n}\) wherem
is the mean of theXi
elements andn
the size of the population. Use this mode if the data represents the entire population.
scope (
Optional
[Scope
]) – The scope of the aggregation. WhenNone
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.
 Return type