# Formula widget

Formula Widget allows you to derive Key Performance Indicators (KPIs) and metrics by performing operations directly from your source data.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-82457fde2ed13591ff9c8b59e85e5013af06941b%2Fimage.png?alt=media" alt=""><figcaption><p><em>Using Formula Widgets in Builder</em></p></figcaption></figure>

### Widget Data

When configuring the Formula Widget calculations, you have the flexibility to choose in the Data section from a *provided aggregation list* or to set a *custom aggregation*.

The *provided aggregation list* options include `COUNT`, `AVG`, `MAX`, `MIN`, and `SUM`, offering a range of commonly used operations. When using these aggregation options, you simply need to specify the field from your data source that you want to aggregate.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-ab7d20b61f1d8b0053e5e44cafa0c854ae95318c%2Fimage.png?alt=media" alt=""><figcaption><p><em>Provided aggregations in Formula Widget</em></p></figcaption></figure>

For more complex and custom calculations, you can select the *custom aggregation* option to create your own SQL Expression. With this option, you can use a wide range of SQL functions, operators and syntax using single or multiple columns from your data source.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-813d41b6ec4e8b5f1af51386abeb5b6df3c44e5d%2Fimage.png?alt=media" alt=""><figcaption><p><em>Custom aggregation using SQL Expression</em></p></figcaption></figure>

{% hint style="info" %}
Custom aggregation option in Formula Widget is not available for pre-generated Tilesets.
{% endhint %}

### Widget Display

From the Display options, you can set the **format** of the data displayed in the widget as well as adding **notes** which support [Markdown syntax](https://www.markdownguide.org/basic-syntax/) to provide further context your widget.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-3b2e4ec775b212ad0d41ab6b86fe2e3c24952907%2Fimage.png?alt=media" alt=""><figcaption><p><em>Using display options to set formatting and add notes</em></p></figcaption></figure>

### Widget Behavior

Within the Behavior section, you can define how your widget operates by choosing between **"Viewport" or "Global" modes**. Additionally, you can make your widgets **collapsible**, allowing you to hide them when needed. Learn more about widget behavior [here](https://docs.carto.com/carto-user-manual/maps/widgets/..#widget-behaviour).
