atoti.agg.max_member module

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 order of the given level) is returned.

Parameters

Example

>>> df = pd.DataFrame(
...     columns=["Continent", "City", "Price"],
...     data=[
...         ("Europe", "Paris", 200.0),
...         ("Europe", "Berlin", 150.0),
...         ("Europe", "London", 240.0),
...         ("North America", "New York", 270.0),
...     ],
... )
>>> table = session.read_pandas(
...     df,
...     table_name="City price table",
... )
>>> table.head()
       Continent      City  Price
0         Europe     Paris  200.0
1         Europe    Berlin  150.0
2         Europe    London  240.0
3  North America  New York  270.0
>>> cube = session.create_cube(table, mode="manual")
>>> h, l, m = cube.hierarchies, cube.levels, cube.measures
>>> h["Geography"] = [table["Continent"], table["City"]]
>>> m["Price"] = tt.value(table["Price"])
>>> m["City with maximum price"] = tt.agg.max_member(m["Price"], l["City"])

At the given level, the measure is equal to the current member of the City level:

>>> cube.query(m["City with maximum price"], levels=[l["City"]])
                       City with maximum price
Continent     City
Europe        Berlin                    Berlin
              London                    London
              Paris                      Paris
North America New York                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 maximum price"], levels=[l["Continent"]])
              City with maximum price
Continent
Europe                         London
North America                New York

At the top level, the measure is equal to the city with the maximum price across all continents:

>>> cube.query(m["City with maximum price"])
  City with maximum price
0                New York
Return type

MeasureDescription