> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a calculation to a widget

> How to define a calculated measure or a calculated member on a single widget in Atoti UI with the Add a calculation submenu of tables and charts, how such a calculation is stored in the widget's query rather than on the cube, and how to edit or delete it afterwards.

A calculation added from a widget belongs to that widget's [query](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/create-a-dashboard/widgets/edit-an-mdx-query.md) instead of being saved on the cube.

Create a calculation in a widget for an ad hoc formula.
It avoids adding to the cube something that only makes sense in that widget's context.
When several widgets, dashboards or users need the same formula, define it on the cube instead.
See [calculated measures](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/modify-the-cube-from-the-ui/calculated-measures.md) or [calculated members](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/modify-the-cube-from-the-ui/calculated-members.md).

## How to add a calculation

1. Right-click a table or a chart, and open the **Add a calculation** submenu.
2. Select **Measures** to define a [calculated measure](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/modify-the-cube-from-the-ui/calculated-measures.md#create-a-calculated-measure), or a hierarchy to define a [calculated member](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/modify-the-cube-from-the-ui/calculated-members.md#how-to-create-a-calculated-member) on it.
3. Fill in the editor that opens at the click location, then click **Apply**.

The new measure or member appears in the widget, after those already displayed.
Like the other members, it can then be [reordered](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/analyze-data/sort-data.md#reorder-members-manually).

The submenu lists a **Measures** entry, plus one entry per hierarchy displayed by the widget.
Calculations cannot be created on virtual hierarchies, so those entries are disabled.

![The context menu of a pivot table, with the Add a calculation submenu open
and listing New row, New column, a Measures entry and the Currency
hierarchy](https://mintcdn.com/activeviam/tnlF9V1NnB9wc5to/data-visualization/atoti-ui/5.2/static/img/user-guide/analyze-data/add-a-calculation-to-a-widget/add-a-calculation-submenu.png?fit=max\&auto=format\&n=tnlF9V1NnB9wc5to\&q=85\&s=c90afd495906e4b7be69efbe1a805cdf)

> [!NOTE]
>
> Displaying a calculated member added this way also reveals the calculated
> members that the cube defines on the same hierarchy. A query asks for both at
> once.

## How to add a single row or column

Some calculations belong in a hierarchy, others make more sense as a single row or column.

On an axis crossing several hierarchies, a calculated measure or member materializes under every parent.
And its formula can refer to members of its own hierarchy, not to the rows or columns the widget displays as these rows and columns each represent one member per hierarchy of the axis.

On the other hand, **New row** and **New column** add a single row or column, under one chosen position.
And their formula can refer to the rows and columns themselves, such as one measure for one currency minus another measure at another currency.

1. Right-click a table, and open the **Add a calculation** submenu.
2. Select **New row** or **New column**.
3. Name the calculation, and pick in **Add under** the position it is nested under.
4. Write its formula, clicking positions in the tree on the left to insert them.
5. Click **Apply**.

Reopening the popover lists the calculations already on the axis, marked with an **fx** icon.
Right-click one to **Edit** or **Delete** it.
A calculation created before a hierarchy was added to the axis can only be deleted: recreating it would move it.
The list also shows the filtered columns and rows.
To edit them, see [Filter a column or a row](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/analyze-data/filter-a-column-or-a-row.md).

## Where does the calculation live?

Storing the calculation in the widget's query, instead of on the cube, has a few consequences:

* It is part of the widget's state, so saving the widget or the dashboard holding it keeps the calculation.
* It follows the widget when the widget is copied.
* The other widgets are left untouched, including those built on the same cube.
* The cube is left untouched too, so the calculation stays invisible to the other users.

## How to edit or delete a calculation

1. Reopen the **Add a calculation** submenu.
2. Select **Measures**, or the hierarchy holding the calculation.
3. Find the calculation in the list within the popover.
4. Right-click it and select **Edit \{name}** or **Delete \{name}**.

Widget calculated measures can also be edited from the [**Fields** tab](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/create-a-dashboard/widgets/add-fields.md), by clicking the pencil icon on its tile.

The submenu also lists the measures and members coming from the cube, but their **Edit** and **Delete** items are disabled.
Those are managed from the **Data model**, as explained in [calculated measures](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/modify-the-cube-from-the-ui/calculated-measures.md) and [calculated members](https://docs.activeviam.com/data-visualization/atoti-ui/5.2/user-guide/modify-the-cube-from-the-ui/calculated-members.md).
