# Building Reactive Metrics Dashboards

{% hint style="success" %}

## PRO TIP: **Unlock a Faster, More Powerful Way to Build REactive Metrics Dashboards**

Before diving in, know that while this tutorial guides you through building a reactive metric dashboard list using Salesforce Flow components, you can achieve the same results—quicker, easier, and with even more flexibility—by leveraging [**Avonni Dynamic Components**](https://docs.avonnicomponents.com/projects/dynamic-components/building-basics-components/enhanced-related-list) for Lightning Pages..
{% endhint %}

## Overview <a href="#overview" id="overview"></a>

This tutorial guides you through building a reactive dashboard in Avonni Flow, featuring dynamic metrics that respond to data table selections.

### **Example scenario** <a href="#example-scenario" id="example-scenario"></a>

Imagine a dashboard displaying a list of accounts in a data table. As users select accounts, the metrics at the top dynamically update to show total revenue, the number of open opportunities, and the total value of those opportunities for the selected accounts. This empowers users to analyze and understand key performance indicators quickly.

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252FT0qNqksgfqFo1sJmRclO%252F2024-10-04_15-33-52%2520%281%29.gif%3Falt%3Dmedia%26token%3Dd5399a9d-22cd-4f41-b0c4-6154e2724e92&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=b0e0f3b7&#x26;sv=2" alt=""><figcaption></figcaption></figure>

## Guided Steps <a href="#guided-steps" id="guided-steps"></a>

This tutorial will walk you through creating an interactive dashboard in Avonni Flow, where metrics dynamically update based on selections made in a data table.

### **1. Set Up the Data Table** <a href="#id-1.-set-up-the-data-table" id="id-1.-set-up-the-data-table"></a>

* **Drag and Drop:** From the Avonni Components palette in Flow Builder, drag the "Data Table" component onto your screen.
* **Configure Data Source:** Select your desired data source. This could be a Salesforce object (e.g., Account, Opportunity) or a collection variable from a previous step in your flow.

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252F2OhPPKWvyNXX6WJEHYMT%252F2024-10-07_09-49-26.png%3Falt%3Dmedia%26token%3Dfb20e9cb-6c16-45a3-b1b2-7224cb83c7b3&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=e4596323&#x26;sv=2" alt=""><figcaption></figcaption></figure>

* **Add Columns:** Drag the relevant fields from your data source onto the data table to create columns—Configure column settings (labels, formatting, etc.) as needed.

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252Fqi4NR7GuA5RN19vwX2Ma%252F2024-10-07_09-50-13.png%3Falt%3Dmedia%26token%3D5ee37d00-daf9-4ad2-a8b1-fc35d2ddb9c4&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=3d36238b&#x26;sv=2" alt=""><figcaption></figcaption></figure>

### **2. Create the Metrics Section** <a href="#id-2.-create-the-metrics-section" id="id-2.-create-the-metrics-section"></a>

* **Add a Section:** Drag a "Section" component onto your screen and configure it to have three columns. This will provide a structured layout for your metrics.

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252FVHl9EWB22gpsrNYjZnxu%252F2024-10-07_09-48-28.png%3Falt%3Dmedia%26token%3Da1c93dd5-e620-44d5-b67c-41f660535db0&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=a581a884&#x26;sv=2" alt=""><figcaption></figcaption></figure>

* **Add Metric Components:** Drag three "Metric" components into the section, one per column.

### **3. Configure the First Metric** <a href="#id-3.-configure-the-first-metric" id="id-3.-configure-the-first-metric"></a>

* **Set Query Value:** In the first metric component, choose "Query" as the value source.
* **Select Object and Field:** Select the relevant Salesforce object (e.g., Opportunity) and the field you want to aggregate (e.g., Amount).
* **Choose Aggregate Function:** To calculate the metric value, select the appropriate aggregate function (e.g., SUM, AVG, COUNT).

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252FZzGtAf6uhf3nbNntIMSR%252F2024-10-07_09-47-39.png%3Falt%3Dmedia%26token%3D9d567b68-aced-4dc5-9991-9dcb1f24b487&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=277057bb&#x26;sv=2" alt=""><figcaption></figcaption></figure>

### **4. Make the Metric Reactive** <a href="#id-4.-make-the-metric-reactive" id="id-4.-make-the-metric-reactive"></a>

* **Create a Formula Text Variable:** In your flow, create a new resource of type "Formula Text." This variable will dynamically filter the metric's query based on the data table selection.
* **Formula Syntax:** Use the following syntax for the formula:

  Copy

  ```
  "Id IN ("&{!dataTable.selectedRowsKeyValueCommaSeparated}&")" 
  ```

  This formula constructs a string that filters records by their IDs, matching the IDs of the rows selected in the data table. `{!dataTable.selectedRowsKeyValueCommaSeparated}` retrieves the selected row IDs.

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252F88lxKFyFTfMwWXU9lDol%252F2024-10-07_09-47-03.png%3Falt%3Dmedia%26token%3D96c6c7c1-9fcf-4334-b1b3-25a9fee3fce1&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=c469cfd8&#x26;sv=2" alt=""><figcaption></figcaption></figure>

* **Connect the Formula to the Metric:** Use the formula text variable in the "Where Clause" field in the metric component's query configuration.

<figure><img src="https://docs.avonnicomponents.com/~gitbook/image?url=https%3A%2F%2F27923732-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F1FUd4apB9YHgCEMUFbVb%252Fuploads%252FMamY659jkq484zVZHoXj%252F2024-10-07_09-45-58%2520%282%29.gif%3Falt%3Dmedia%26token%3D86919e3a-0bc5-48d1-b71b-f75be832e11d&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=c5849e2b&#x26;sv=2" alt=""><figcaption></figcaption></figure>

### **5. Repeat for Other Metrics** <a href="#id-5.-repeat-for-other-metrics" id="id-5.-repeat-for-other-metrics"></a>

Repeat steps 3 and 4 for the remaining two metric components, adjusting the object, field, and aggregate function as needed.

### **6. Test and Refine** <a href="#id-6.-test-and-refine" id="id-6.-test-and-refine"></a>

Save your flow and test it. Observe how the metrics dynamically update as you select different rows in the data table. Refine the formatting and layout of your dashboard to ensure clarity and visual appeal.

Following these steps, you'll create a dynamic and interactive dashboard that empowers users to explore data and gain valuable insights in real-time.
