atoti.function.at module#

atoti.at(measure, coordinates, /)#

Return a measure equal to the passed measure at some other coordinates of the cube.

Parameters
  • measure (MeasureDescription) – The measure to take at other coordinates.

  • coordinates (Mapping[Level, Any]) –

    A {level_to_shift_on: value_to_shift_to} mapping.

    >>> df = pd.DataFrame(
    ...     columns=[
    ...         "Country",
    ...         "City",
    ...         "Target Country",
    ...         "Target City",
    ...         "Quantity",
    ...     ],
    ...     data=[
    ...         ("Germany", "Berlin", "UK", "London", 15),
    ...         ("UK", "London", "Germany", "Berlin", 24),
    ...         ("USA", "New York", "UK", "London", 10),
    ...         ("USA", "New York", "France", "Paris", 3),
    ...         ("USA", "Seattle", "Germany", "Berlin", 3),
    ...     ],
    ... )
    >>> table = session.read_pandas(df, table_name="At")
    >>> cube = session.create_cube(table, mode="manual")
    >>> h, l, m = cube.hierarchies, cube.levels, cube.measures
    >>> h["Geography"] = [table["Country"], table["City"]]
    >>> h["Target Geography"] = [
    ...     table["Target Country"],
    ...     table["Target City"],
    ... ]
    >>> m["Quantity.SUM"] = tt.agg.sum(table["Quantity"])
    >>> # Using a constant matching an existing member of the key level
    >>> m["USA quantity"] = tt.at(
    ...     m["Quantity.SUM"], {l["Country"]: "USA"}
    ... )
    >>> cube.query(
    ...     m["Quantity.SUM"],
    ...     m["USA quantity"],
    ...     levels=[l["Country"]],
    ... )
            Quantity.SUM USA quantity
    Country
    Germany           15           16
    UK                24           16
    USA               16           16
    >>> # Using another level whose current member the key level will be shifted to
    >>> m["Target quantity"] = tt.at(
    ...     m["Quantity.SUM"],
    ...     {
    ...         l["Country"]: l["Target Country"],
    ...         l["City"]: l["Target City"],
    ...     },
    ... )
    >>> cube.query(
    ...     m["Quantity.SUM"],
    ...     m["Target quantity"],
    ...     levels=[l["City"], l["Target City"]],
    ... )
                                                Quantity.SUM Target quantity
    Country City     Target Country Target City
    Germany Berlin   UK             London                15              24
    UK      London   Germany        Berlin                24              15
    USA     New York France         Paris                  3
                     UK             London                10              24
            Seattle  Germany        Berlin                 3              15
    

    If this other level is not expressed, the shifting will not be done.

Return type

MeasureDescription