# 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="/files/a9duJnt2xt3b0bWBXkFv" 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="/files/QyodO9IvyEUVqyEUuclE" 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="/files/uyoqXSsfmEj2ySxtF2Bg" 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="/files/B9TM4ndha9TNj2mjd9yh" 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](/carto-user-manual/maps/widgets.md#widget-behaviour).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.carto.com/carto-user-manual/maps/widgets/formula-widget.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
