atoti.Cube.create_parameter_hierarchy_from_members()#

Cube.create_parameter_hierarchy_from_members(name, members, *, data_type=None, index_measure_name=None)#

Create a single-level hierarchy with the given members.

It can be used as a parameter hierarchy in advanced analyzes.

Parameters:
  • name (str) – The name of hierarchy and its single level.

  • members (Collection[Any]) – The members of the hierarchy.

  • data_type (DataType | None) – The type with which the members will be stored. Automatically inferred by default.

  • index_measure_name (str | None) – The name of the indexing measure to create for this hierarchy, if any.

Example

>>> df = pd.DataFrame(
...     {
...         "Seller": ["Seller_1", "Seller_2", "Seller_3"],
...         "Prices": [
...             [2.5, 49.99, 3.0, 54.99],
...             [2.6, 50.99, 2.8, 57.99],
...             [2.99, 44.99, 3.6, 59.99],
...         ],
...     }
... )
>>> table = session.read_pandas(df, table_name="Seller prices")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> cube.create_parameter_hierarchy_from_members(
...     "ProductID",
...     ["aBk3", "ceJ4", "aBk5", "ceJ9"],
...     index_measure_name="Product index",
... )
>>> m["Prices"] = tt.agg.single_value(table["Prices"])
>>> m["Product price"] = m["Prices"][m["Product index"]]
>>> cube.query(
...     m["Product price"],
...     levels=[l["Seller"], l["ProductID"]],
... )
                   Product price
Seller   ProductID
Seller_1 aBk3               2.50
         aBk5               3.00
         ceJ4              49.99
         ceJ9              54.99
Seller_2 aBk3               2.60
         aBk5               2.80
         ceJ4              50.99
         ceJ9              57.99
Seller_3 aBk3               2.99
         aBk5               3.60
         ceJ4              44.99
         ceJ9              59.99