Calculated Fields

Add custom calculations at the level of a single visual.

ℹ️ Works on Both Kinds of Visual Calculated Fields can be used in query-based and drag-and-drop visuals alike.

Say you want to display monthly sales, but you only have the fields Quantity Ordered and Price Each. To get Total Sales, you need the formula Total Sales = Quantity Ordered * Price Each.

Before

A table without the Total Sales column

After

The same table with a Total Sales calculated field
⚠️ Tables Only Calculated Fields can only be added to table visualizations. For any other visual type — a bar or line chart, say — convert the visual to a Table, add the calculated fields, then convert it back.

Step 1: Add a Calculated Field

In the tile menu, click + Calculated Field under Query & Transform.

The + Calculated Field option in the tile menu

Step 2: The Formula Bar

A formula bar appears, along with column numbers against each column of the table.

The formula bar and numbered columns

Step 3: Write the Formula

Add the formula the same way you would in a spreadsheet. We want Total Sales = Quantity Ordered * Price Each — that is, Total Sales = col2 * col3 — so the formula is = col2 * col3.

ℹ️ The Formula Goes Into the Query PersivX adds the formula to the query used to fetch data, so you can use any function or macro supported by the datasource you're connected to. Connected to MySQL, for example, =CONCAT(col1, '-', col3) works as a calculated field.
Entering a formula in the formula bar

Step 4: Apply It

Click anywhere outside the formula bar and PersivX adds the new field to the table.

The calculated field added to the table

Step 5: Move and Rename

Move and rename the column. It can be customized exactly like any other column on a tile.

Renaming the calculated column

Step 6: Hide the Source Fields

If Quantity Ordered and Price Each are no longer needed on the visual, hide them.

⚠️ Hide, Don't Remove Do not remove the underlying fields from the visual, or the calculated field will stop working as expected. Hide them instead. If you need aggregations like SUM() or MAX(), create custom attributes instead.
Hiding the source columns while keeping them on the visual

Step 7: Convert to Another Visual Type

The tile can now be converted to other visual types.

The calculated field rendered in other visual types

Important Points to Remember

  1. Calculated Fields never change the number of rows in a result — they only add columns.
  2. You can add as many calculated fields as you need on a single tile.
  3. A calculated field can be used to build further calculated fields. For example, adding a field showing 2 * Total Sales:
A calculated field built from another calculated field
💡 Next Calculated Fields live at tile level, so the formula cannot be reused across tiles. To define a formula once and use it everywhere, see Custom Attributes.