> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/flow/tutorials/components/metric/add-a-trend-against-a-target.md).

# Add a trend against a target

Color a Metric red or green against a quarterly target with Show Trend Color, and show the target or the gap next to it as a secondary value.

The sales team's target this quarter is $500,000. On the forecast screen, the manager wants the won total to turn red while the team is below target and green once it is past, with the target written next to it. The Metric does this with **Show Trend Color** on the primary value and a secondary value.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FhIPJOfuD76qWfJQ8mJA8%2Fmetric-trend-result.png?alt=media" alt="Avonni Metric below target: US$482,500 in red with a down caret, Target US$500,000 under it" width="450"><figcaption><p>Below the 500,000 breakpoint, the total takes the negative color and a down caret.</p></figcaption></figure>

## Before you start

* A Metric that shows the won total. [Show a KPI from a query](https://docs.avonnicomponents.com/flow/tutorials/components/metric/show-a-kpi-from-a-query.md) builds it.
* The target as a number. This tutorial types `500000`. If the target lives on a record, get it with Get Records first and map it.

## Steps

{% stepper %}
{% step %}

### Turn on the trend on the won total

Open the Metric in the Component Builder. In **Primary Metric**:

* Turn on **Show Trend Color**.
* **Trend Breakpoint Value**: `500000`. A value above it is positive, equal is neutral, below is negative.
* **Trend Icon**: **Caret**, so the direction also reads without color.

The colors come from the **Trend** group of the **Style** tab: change **Negative Color** and **Positive Color** there if your screen uses other shades.
{% endstep %}

{% step %}

### Show the target as a secondary value

In **Secondary Metric**:

* **Format Style**: **Currency**, **Currency Code**: `USD`, **Maximum Fraction Digits**: `0`.
* **Secondary Value**: `500000`.
* **Prefix**: `Target`.
* **Position**: **Bottom**, so the target sits under the total on a narrow screen.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2F3MB8yRHjt0lras0OuMBt%2Fmetric-trend-secondary-panel.png?alt=media" alt="Component Builder: primary Show Trend Color on, Trend Breakpoint Value 500,000, Trend Icon Caret; Secondary Metric with Format Style Currency, Secondary Value 500,000, Prefix Target, Position Bottom, Currency Code USD" width="320"><figcaption><p>The trend on the primary value, and the target as a secondary value under it.</p></figcaption></figure>
{% endstep %}

{% step %}

### Optional: show the gap instead of the target

The secondary value never computes anything from the primary one. To show "8% below target" as a colored badge, compute the gap in the flow and map it:

1. Get the won total into a flow variable, for example `{!WonAmount}`. The Metric's own query cannot feed it: the Metric returns no output for its value, only the click outputs. Use Get Records on the Opportunities that match the Metric's filter (`StageName` equals `Closed Won`, `CloseDate` in the current quarter) and a Loop that adds each `Amount`.
2. Create a Number formula `GapToTarget`: `ROUND(({!WonAmount} - 500000) / 500000 * 100, 0)`.
3. Set the secondary **Format Style** to **Percent Fixed**, map **Secondary Value** to `{!GapToTarget}`, set **Value Sign** to **Positive and Negative** and clear the **Prefix**.
4. Turn on the secondary **Show Trend Color** and set the secondary **Trend Breakpoint Value** to `0`.

The secondary **Trend Breakpoint Value** only appears while the primary **Show Trend Color** is on, as the previous step set it. The badge colors and corner radius come from the **Secondary Trend** style group.
{% endstep %}

{% step %}

### Save and test

Run the flow with **Debug**. With $482,500 won, the total shows in the negative color with a down caret, and `Target $500,000` sits under it. Close one more deal as **Closed Won** for $20,000, rerun, and the total turns to the positive color with an up caret.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
A small line chart of the trend is not part of the Metric. Put an Avonni Chart set to a line under the Metric in the same screen for that.
{% endhint %}

## Related tutorials

* [Show a KPI from a query](https://docs.avonnicomponents.com/flow/tutorials/components/metric/show-a-kpi-from-a-query.md): the won total this tutorial colors.
* [Format money, percent and dates](https://docs.avonnicomponents.com/flow/tutorials/components/metric/format-money-percent-and-dates.md): **Percent Fixed** and **Value Sign** in detail.
* [Branch the flow on a metric click](https://docs.avonnicomponents.com/flow/tutorials/components/metric/branch-the-flow-on-a-metric-click.md): let the manager click the total to see the deals behind it.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/flow/tutorials/components/metric/add-a-trend-against-a-target.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
