atoti.first()#

atoti.first(measure, on, /, *, partitioning=None)#

Return a measure equal to the first value of the passed measure on the given level.

Parameters:
  • measure (VariableMeasureConvertible) – The measure to shift.

  • on (Level) – The level to shift on.

  • partitioning (Level | None) – The level in the hierarchy at which to start over.

Return type:

MeasureDescription

Example

>>> from datetime import date
>>> df = pd.DataFrame(
...     columns=["Date", "Quantity"],
...     data=[
...         (date(2019, 7, 2), 15),
...         (date(2019, 7, 1), 20),
...         (date(2019, 6, 1), 25),
...         (date(2019, 6, 2), 15),
...         (date(2019, 6, 30), 5),
...     ],
... )
>>> table = session.read_pandas(df, table_name="CumulativeTimePeriod")
>>> cube = session.create_cube(table, mode="manual")
>>> l, m = cube.levels, cube.measures
>>> cube.create_date_hierarchy("Date", column=table["Date"])
>>> m["Quantity.SUM"] = tt.agg.sum(table["Quantity"])
>>> m["Quantity first day"] = tt.first(m["Quantity.SUM"], l["Day"])
>>> m["Quantity first day of month"] = tt.first(
...     m["Quantity.SUM"], l["Day"], partitioning=l["Month"]
... )
>>> cube.query(
...     m["Quantity.SUM"],
...     m["Quantity first day"],
...     m["Quantity first day of month"],
...     levels=[l["Day"]],
...     include_totals=True,
... )
                Quantity.SUM Quantity first day Quantity first day of month
Year  Month Day
Total                     80                 25
2019                      80                 25
      6                   45                 25                          25
            1             25                 25                          25
            2             15                 25                          25
            30             5                 25                          25
      7                   35                 25                          20
            1             20                 25                          20
            2             15                 25                          20