> 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/dynamic-components/tutorials/components/chart/track-won-revenue-by-month.md).

# Track Won Revenue by Month

Build a Line chart of won Opportunity revenue by year and month, keeping January in different years separate and checking each monthly total.

A sales manager needs to compare won revenue across years without combining every January into one point. Build an Avonni Line chart that groups Opportunity Close Date by year and month, then check each point against the won records behind it.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2F6lVARUpkWoAj56Iz6dc6%2Ftutorial-won-revenue-result.jpg?alt=media" alt="Line chart preview of won Opportunity revenue with January in each year shown separately"><figcaption><p>Builder preview: won monthly totals are 30,000, 25,000, 40,000 and 60,000 across the four distinct year-and-month groups.</p></figcaption></figure>

[View this capture at full size](https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2F6lVARUpkWoAj56Iz6dc6%2Ftutorial-won-revenue-result.jpg?alt=media)

## Before You Start

* Open a Dynamic Component you can edit, or follow [Creating a new component](https://docs.avonnicomponents.com/dynamic-components/avonni-components-app/creating-a-new-component.md).
* You need access to Opportunity records and their Close Date, Amount and won status. Use one currency for this exercise.
* Choose won opportunities in at least two years, including January in both years. Include at least two won records in one month so you can verify a sum. Keep one open and one lost opportunity in the same test period to check that the filter excludes them.
* See the [Chart reference](https://docs.avonnicomponents.com/dynamic-components/components/chart.md) and [Query](https://docs.avonnicomponents.com/dynamic-components/component-builder/data-sources/query.md) for the available settings and filters.

## Steps

{% stepper %}
{% step %}

### Write Down the Monthly Totals First

Use your own opportunities, or prepare these sample values in a sandbox. Give all seven record names the prefix `Chart Docs Trend -` so you can limit the query to this exercise.

| Close Date   | Stage         | Amount  |
| ------------ | ------------- | ------- |
| `2025-01-10` | Closed Won    | `10000` |
| `2025-01-20` | Closed Won    | `20000` |
| `2025-02-10` | Closed Won    | `25000` |
| `2026-01-10` | Closed Won    | `40000` |
| `2026-01-15` | Qualification | `99000` |
| `2026-02-10` | Closed Won    | `60000` |
| `2026-02-15` | Closed Lost   | `88000` |

Add the won Amount values separately for each year and month:

| Year and month | Expected won total | Included opportunities |
| -------------- | ------------------ | ---------------------- |
| January 2025   | `30000`            | 2                      |
| February 2025  | `25000`            | 1                      |
| January 2026   | `40000`            | 1                      |
| February 2026  | `60000`            | 1                      |
| Total          | `155000`           | 5                      |

Keep January in the first year separate from January in the second year. The open `99000` and lost `88000` records are filter controls; do not include them in the won totals.

For your own data, write down your own monthly totals using the same query scope. A plausible trend line does not prove that the filter or date grouping is correct.
{% endstep %}

{% step %}

### Add a Line Chart and Query Won Opportunities

Add **Chart** from the **Component Library** and select it on the canvas. In **Edit Chart > Properties > Content**, set **Type** to **Line**.

In **Data Source**, select **Query**. In **Records**, choose or create an Opportunity query. Use **Edit the query** to check these requirements:

| Query requirement | Set it to                                      |
| ----------------- | ---------------------------------------------- |
| Object            | Opportunity                                    |
| Won records only  | The won flag is true (`IsWon = true`)          |
| Sample scope      | Name (`Name`) starts with `Chart Docs Trend -` |

Combine the two conditions with AND. Set the query's sorting to Close Date ascending. Keep the same sample scope in your independent check.

The sample query needs no date filter because the name rule isolates these seven records. For your own revenue view, replace that rule with your business scope and add Close Date conditions if you want a fixed reporting period.

Filtering only on closed status would include lost opportunities too. Use the won condition to measure won revenue.
{% endstep %}

{% step %}

### Keep Each Year and Month Separate

Open **Data Mappings > X-Axis**. Add Close Date (`CloseDate`) as the **Field** and set **Group** to **Year-Month**.

Turn on **Display Full Month Label** if you want the month name spelled out.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FE1JIQhkNlfPFzDCO4qHh%2Ftutorial-won-revenue-year-month.jpg?alt=media" alt="Line X-Axis mapping with Close Date grouped by Year-Month" width="480"><figcaption><p>Year-Month keeps January from different years in separate groups.</p></figcaption></figure>

[View this capture at full size](https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FE1JIQhkNlfPFzDCO4qHh%2Ftutorial-won-revenue-year-month.jpg?alt=media)

**Month** groups the same month across years together. **Year-Month** retains both parts, so January in each year remains a separate group.
{% endstep %}

{% step %}

### Sum the Won Amounts

Open **Data Mappings > Y-Axis** and add one entry:

| Setting      | Value             |
| ------------ | ----------------- |
| Field        | Amount (`Amount`) |
| Measures     | Sum               |
| Format Style | Currency Rounded  |
| Multiplier   | `1`               |

Leave **Lines** empty. It is an additional grouping for separate lines; this example needs one revenue series.

In **Content**, set **Title** to `Won revenue by month`, **X Title** to `Month`, **Y Title** to `Won revenue ($)` and **Palette** to **Aurora**. Adapt the currency label to your records; the sample's `$` display does not identify a currency ISO code.

In **Chart**, turn on **Show Points** and **Show Values in Chart Lines** to make the monthly points and values visible. Leave **Show Legend** off for this single series. In **Style > Size**, set **Height** to `400 px` and **Width** to `760 px`, then check that the date labels remain readable.
{% endstep %}

{% step %}

### Check Both January Points

Click **Preview**. Find January in each year and compare each plotted value with its own source total. They must remain separate points with separate year-and-month labels.

In January 2025, `10000 + 20000 = 30000`. January 2026 must remain `40000`, rather than combining into one January total of `70000`. Check February 2025 is `25000` and February 2026 is `60000`. All four points add up to `155000`. The open and lost controls must not contribute to any point.

Check the displayed month order. Do not infer zero revenue from an absent month; confirm whether your source records contain won opportunities for that month.
{% endstep %}

{% step %}

### Save and Test

Click **Save** after the filters, both January groups and the monthly sums match your records. The figures show the Builder preview; they do not prove behavior on a deployed Lightning Page.

When you are ready to share your own component, follow [Publishing your Dynamic Components](https://docs.avonnicomponents.com/dynamic-components/core-concepts/publishing-your-dynamic-components.md) to activate the version and place it on a Lightning Page.

Repeat the check as a person who will view the page. Queries use that person's Salesforce access, so confirm their visible opportunities and totals separately.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>There is only one January across several years</summary>

Open the Close Date **X-Axis** entry and change **Group** from **Month** to **Year-Month**. Check the year as well as the month on the resulting labels.

</details>

<details>

<summary>The monthly total includes open or lost opportunities</summary>

Check the won condition (`IsWon = true`) and the sample-name scope. If you added a reporting period for your own data, check those Close Date conditions too. Use the same conditions in your independent total. A date grouping does not remove unwanted records.

</details>

<details>

<summary>Several lines appear</summary>

Check **Data Mappings > Lines**. Remove an additional grouping if you intend to show one revenue series. Keep one Amount entry in **Y-Axis** for this example.

</details>

<details>

<summary>The amounts have the wrong scale</summary>

Check that **Measures** is **Sum**, **Multiplier** is `1` and the displayed currency matches your source records. **Currency Rounded** controls display formatting; it does not change which opportunities the query includes.

</details>

## Related Tutorials

* [Compare Total and Average Deal Size](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chart/compare-total-and-average-deal-size.md): compare two calculations over the same open pipeline records.
* [Understand Account Industries](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chart/understand-account-industries.md): use record counts to size whole industry labels.
* [All Chart tutorials](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chart.md): choose another question to answer with Chart.


---

# 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/dynamic-components/tutorials/components/chart/track-won-revenue-by-month.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.
