atoti.function.shift module#

atoti.shift(measure, on, /, *, offset=1)#

Return a measure equal to the passed measure shifted to another member of the hierarchy.

Parameters

Example

>>> df = pd.DataFrame(
...     columns=["Country", "City", "Price"],
...     data=[
...         ("France", "Bordeaux", 1),
...         ("France", "Lyon", 2),
...         ("France", "Paris", 3),
...         ("Germany", "Berlin", 4),
...         ("Germany", "Frankfurt", 5),
...         ("Germany", "Munich", 6),
...     ],
... )
>>> table = session.read_pandas(
...     df,
...     table_name="Shift example",
... )
>>> cube = session.create_cube(table)
>>> h, l, m = cube.hierarchies, cube.levels, cube.measures
>>> m["Shifted Price.SUM"] = tt.shift(m["Price.SUM"], h["City"], offset=2)
>>> cube.query(
...     m["Price.SUM"],
...     m["Shifted Price.SUM"],
...     levels=[l["City"]],
...     include_totals=True,
... )
          Price.SUM Shifted Price.SUM
City
Total            21
Berlin            4                 5
Bordeaux          1                 2
Frankfurt         5                 6
Lyon              2                 3
Munich            6
Paris             3
>>> h["Location"] = [l["Country"], l["City"]]
>>> m["Shifted Price.SUM"] = tt.shift(m["Price.SUM"], h["Location"], offset=1)
>>> cube.query(
...     m["Price.SUM"],
...     m["Shifted Price.SUM"],
...     levels=[
...         l["Shift example", "Location", "Country"],
...         l["Shift example", "Location", "City"],
...     ],
...     include_totals=True,
... )
                  Price.SUM Shifted Price.SUM
Country City
Total                    21
France                    6                15
        Bordeaux          1                 2
        Lyon              2                 3
        Paris             3                 4
Germany                  15
        Berlin            4                 5
        Frankfurt         5                 6
        Munich            6
Return type

MeasureDescription