atoti.function.last module#
- atoti.last(measure, on, /, *, partitioning=None)#
Return a measure equal to the last value of the passed measure on the given level.
- Parameters
- 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 last day"] = tt.last(m["Quantity.SUM"], l["Day"]) >>> m["Quantity last day of month"] = tt.last( ... m["Quantity.SUM"], l["Day"], partitioning=l["Month"] ... ) >>> cube.query( ... m["Quantity.SUM"], ... m["Quantity last day"], ... m["Quantity last day of month"], ... levels=[l["Day"]], ... include_totals=True, ... ) Quantity.SUM Quantity last day Quantity last day of month Year Month Day Total 80 15 2019 80 15 6 45 15 5 1 25 15 5 2 15 15 5 30 5 15 5 7 35 15 15 1 20 15 15 2 15 15 15