> 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/compare-won-revenue-by-lead-source.md).

# Compare Won Revenue by Lead Source

Build a Donut chart of won revenue by lead source, then compare its revenue shares with deal counts to see which sources bring larger wins.

A sales manager wants to know which lead sources contribute the most won revenue. Build an Avonni Donut chart, then change its measure to compare revenue share with deal-count share. A source that brings more deals can still contribute less revenue.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FCH3lz6J3R0H3V37loZLj%2Ftutorial-donut-revenue-result.jpg?alt=media" alt="Donut chart preview comparing won revenue from Web and Partner"><figcaption><p>Builder preview of won revenue by lead source, with Web contributing 40,000 and Partner 100,000.</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%2FCH3lz6J3R0H3V37loZLj%2Ftutorial-donut-revenue-result.jpg?alt=media)

## Before You Start

* Open a Dynamic Component you can edit.
* You need access to Opportunity records and their Lead Source, Amount and won status. Use one currency for this exercise.
* Use opportunities with at least two populated Lead Source values, plus blank-source, open and lost records to test the scope.
* Keep the [Chart reference](https://docs.avonnicomponents.com/dynamic-components/components/chart.md) and [Query guide](https://docs.avonnicomponents.com/dynamic-components/component-builder/data-sources/query.md) available.

## Steps

{% stepper %}
{% step %}

### Prepare Two Different Source Mixes

Use your own data or prepare this sample in a sandbox. Give the sample opportunities names starting with `Chart Docs Donut -` .

| Lead Source | Won opportunities | Amount per opportunity | Expected won revenue |
| ----------- | ----------------- | ---------------------- | -------------------- |
| Web         | 4                 | `10000`                | `40000`              |
| Partner     | 2                 | `50000`                | `100000`             |

The included sample contains six wins worth `140000`. Add one won opportunity of `5000` with no Lead Source, one open opportunity of `99000` and one lost opportunity of `88000` under the same name prefix. These are controls, excluded from the comparison.

Verify that the two source values exist in your org. If you use other values, keep the same counts and amounts and use those labels throughout your check.
{% endstep %}

{% step %}

### Query Won Opportunities with a Known Source

Add **Chart** from the **Component Library**. In **Edit Chart > Properties > Content**, set **Type** to **Donut** and **Title** to `Won revenue by lead source`.

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

* The won flag is true (`IsWon = true`).
* Lead Source (`LeadSource`) is not blank.
* Name (`Name`) starts with `Chart Docs Donut -` .

For your own business view, replace the name condition with your reporting scope. Keep the won and source requirements in your independent check too. Excluding blanks means this chart measures revenue attributed to a known source, rather than all won revenue.
{% endstep %}

{% step %}

### Group Slices and Sum Revenue

In **Data Mappings > Sliced By**, add Lead Source (`LeadSource`) as the **Field**. In **Value**, add one entry:

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

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fg9zoOSj8u7WdofxoI2yX%2Ftutorial-donut-value-mapping.jpg?alt=media" alt="Donut Value mapping with Amount, Sum and Currency Rounded" width="480"><figcaption><p>The Donut Value mapping uses the Amount sum for revenue.</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%2Fg9zoOSj8u7WdofxoI2yX%2Ftutorial-donut-value-mapping.jpg?alt=media)

Turn on **Show Total**, **Show Percentages** and **Show Legend**. Leave **Combine Small Groups into "Others"** off so you can check each source separately.

The currency preset formats the values. It does not convert currencies or change the query scope. Adapt the displayed currency to your records.
{% endstep %}

{% step %}

### Check Each Revenue Share

Click **Preview**. Check Web totals `40000` and Partner totals `100000`, with a combined total of `140000`.

Web contributes `40000 / 140000`, about 29% of revenue. Partner contributes about 71%. The Donut percentages are rounded to whole numbers. Read the labels and legend; do not identify a source by its color alone. Changing the measure can change slice order and which palette color a source receives.

Confirm that the blank-source win, open opportunity and lost opportunity do not affect the total. If the result differs, reconcile the query before changing the measure.
{% endstep %}

{% step %}

### Compare the Same Records by Deal Count

Return to the editor. Keep **Sliced By** and every query condition unchanged. Replace the **Value** entry with **Field** = record ID (`Id`), **Measures** = **Count**, **Format Style** = **Number Rounded** and **Multiplier** = `1`. Change **Title** to `Won deals by lead source`.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fote2haUHonudwzepZiN6%2Ftutorial-donut-count-result.jpg?alt=media" alt="Donut chart preview comparing four Web wins with two Partner wins"><figcaption><p>Builder preview of the same six wins counted by source, rather than summed by Amount.</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%2Fote2haUHonudwzepZiN6%2Ftutorial-donut-count-result.jpg?alt=media)

Open **Preview** again. The total is now `6`: Web contributes four wins, about 67%, and Partner contributes two, about 33%. The largest slice changes because the measure changes, not because the source records changed.

Compare both views before deciding which source deserves attention. Deal counts show volume; summed Amount shows revenue contribution.
{% endstep %}

{% step %}

### Save the Measure Your Audience Needs

Choose the revenue or count version, give it a matching title and click **Save**. Check the total and source labels once more in **Preview**.

The figures show the Builder preview. To share your component on a Lightning Page, follow [Publishing your Dynamic Components](https://docs.avonnicomponents.com/dynamic-components/core-concepts/publishing-your-dynamic-components.md), then repeat the checks with a viewer's Salesforce access.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>The total is larger than expected</summary>

Check `IsWon = true`, the name scope and the exclusion of blank `LeadSource`. A closed-status filter alone can include lost deals. Count or sum the source records with the exact same conditions as the chart.

</details>

<details>

<summary>The chart still looks like a count after changing the title</summary>

A title does not change the calculation. Check the **Value** entry: use Amount and **Sum** for revenue, or `Id` and **Count** for deal volume. Update **Format Style** with the measure.

</details>

<details>

<summary>A source has disappeared into Others</summary>

Turn off **Combine Small Groups into "Others"** while validating individual sources. Check the query for missing source values before interpreting a missing slice as zero revenue.

</details>

## Related Tutorials

* [Track Won Revenue by Month](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chart/track-won-revenue-by-month.md): compare won revenue over distinct year-and-month groups.
* [Measure Won Revenue Against a Target](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chart/measure-won-revenue-against-a-target.md): compare a won total with a fixed monetary goal.
* [Understand Account Industries](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chart/understand-account-industries.md): use record counts to compare account categories.


---

# 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/compare-won-revenue-by-lead-source.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.
