Select accounts in a Data Table and Avonni Metrics show their total revenue and open opportunities.

Build a small dashboard in a screen flow: metrics that update when users select accounts in a table. For Salesforce admins who want quick numbers without a report.
Hello and welcome to this new video tutorial about the Avonni Components package for screen flows. Today I'm going to show you how to create dynamic Metric dashboards based on selection made on a Data Table. So that's exactly the example you can see here on my screen. I have one screen flow with Metrics, Avonni Metrics at the top, and with a Data Table displaying a list of accounts. What I did, I set up Metrics to be reactive based on the Data Table. So if I'm selecting an account or multiple accounts, it will automatically calculate and refresh the Metrics based on the information selected. So the Metrics are reactive, and today I'm going to show you how to build this live example directly into your screen flows. So let's dive in. Okay, let's create a
screen flow from scratch. So I will select Screen Flow, and from there I will drag the Screen element. Enter label. Okay, I want to hide Header and Footer. Now, first step, we need to drag the Data Table. So this is really the first component we need to set up. It's really to configure the Data Table. An easy way to configure the Data Table: open the Component Builder. And here we want to display account information, very basic setup. I scroll down to the data source section to be able to connect my Salesforce data with the component. Here we do a query, so I will query directly inside the component the Account object. Perfect. And now from there, on the left side, I have all the fields available for my Data Table. So I will just drag the name, the account number. Feel free to, you know, add the fields you want on the Data Table, maybe the industry, number of employees. I mean, it's really up to you. And you can also fine-tune the settings: linkify the name, account number. Okay, that's... let's maybe add a header. Let's say My Accounts for the title, and let's select the avatar. Okay, pretty basic setup. Once again, if you like, you can also make all fields searchable and fine-tune the Data Table the way you need to set up the Data Table. Okay, next. If you remember the example, so if we take back the example, right there at the top I have Metrics, the Avonni Metrics at the top, three Avonni Metrics. So what I did, and this is exactly what I'm doing now, I will add a
Section, and on this Section element at the top, just add three columns. So now we have three columns, and we can really drag the Metric component inside. So we look for the Metric component, Avonni Metric. Let's name it metric one. Open the Component Builder for the Metric, and then we will just type the label regarding the metric we want to display. So the label will be something like this: Total revenue for selected accounts. And now the value. What would be the value for the total revenue of selected accounts? So this will be a query. Here I'm querying the Account object, the field Annual Revenue, and for the aggregate function I will use sum. Okay, that's perfect. It will automatically calculate this. I can also fine-tune the primary metric to display the format style using currency. Okay, but here I'm just querying all the information coming from my Salesforce, but I need to filter this information based on the selection made on the Data Table. So I need the Metric to be reactive, and for that, the next step is we need to create a formula text variable, and we will use this formula text variable as a filter for the Metric. Maybe I will add some avatar as well, just to fine-tune, and then we will dive into the Metric side, the reactive part. Okay, and we can also fine-tune the style. So if I'd like to see, okay, padding, just for the look and feel, the style of this. Right there, I would just add a border around the component. So let's select a color, size, style solid, and for the radius let's use a token, let's say large. Okay, maybe not large, medium. Okay, we can change the color if we like to make it more dark. Okay, perfect. Okay, now, as I said, we need to make this reactive, so we need to create a formula text variable to make the Metric reactive. So
I will go right there, and then I will select here New Resource, Formula. Let's say query selected accounts. It's Text for the formula text, and now this is the syntax I will use for my formula. I will copy paste the syntax in the video description below, so feel free to copy paste the syntax of the formula and tweak this syntax for your needs. So here, basically, this formula text variable will be used as a filter, so it's like the WHERE clause in our query. Let's start the formula by adding quotation mark twice, and then here basically it will be... so the formula will be ID IN, and then we open bracket, quotation mark as well, and now inside this we'll add this sign. And then what we need to do is we need to add the attribute from the Data Table, and the one we need to select, it's the selected row key value comma separated. Selected row key value comma separated, yes. Okay, perfect. Let's do a quick check on the formula. Syntax is valid, perfect. Again, I will copy paste this formula syntax on the video description. So now the formula is created. I can open back the Screen element, select the Metric, and what I will do here, I will filter this Metric based on the formula. So I will select the formula as our filter. Okay, I will just save this. Let's do a quick test. I will just do a run to see. Okay, I can see the Data Table. Let's select items. Nice, I really like that. It's automatically calculating the amount on the Metric. I just missed the dollar sign, so I just need to, for the primary metric on... let's do it again. I think I did it already on the Metric. Make sure to do it on primary metric, to select format style currency, so just to make sure the currency symbol will be displayed right there. Otherwise, I mean, as expected, that's perfect. Okay, now let's continue our example by adding another Metric component. So right there, next to the first one, I will drag the Metric once
again. Let's name it metric two, or any name you want. And here I like to label... the label will be Number of open opportunities, and the value for that would be the query on the Opportunity object. The field would be the opportunity ID, because I'd like to display the number of open opportunities for each, for all the accounts I'm selecting on the Data Table. So it would be the opportunity ID, and aggregate function would be count. Okay, perfect, 24. That's good, but again, it's not filtered by the selected value of the Data Table, so we need to create another formula text variable that will handle this to be reactive. Okay, let's maybe go back on the Metric, just add an avatar. That would be nice here. And the style, we can apply the same styling. We can copy paste the component properties from one Metric to another one. I will just do it again right from there: medium, medium, medium, and then border color, one, solid. It's always fun to see the style settings and how far you can go by styling the component settings as well. Okay, perfect. Okay, done. Let's create the
formula, formula text. The name would be query total amount opportunities. And again, double quote. Here we have... so okay, that's a different syntax for the formula. Why? Because the filter will be based not on the ID but more on the account ID, because here I'm querying the Opportunity object. So it will be the account ID field IN, and then open bracket, then we will have the double quotation mark, and finally this account ID IN this attribute, the exact same, I mean the same one, selected row key value comma separated for the Data Table, comma separated. Okay. But okay, it's the total amount of open opportunities, so basically I need to tweak the formula once again for the WHERE on my query. So it would be like AND StageName, so the name of the field, StageName field for the Opportunity object, NOT IN, and here we need to open the bracket again. So here we need to type the... okay, Closed Won, and here we need to add... now, oh yes, Closed Lost. Again, I will copy paste the formula syntax. Okay, valid, like that. Okay, perfect. Okay, save. Open the Metric and filter dynamically by the formula value, query total amount opportunities, and save. Again, let's save the flow. Let's do a run again to see how
it's working. Okay, let's do a test. Let's select items. Yes, it's working as expected: number of open opportunities, the total amount, total revenue for selected accounts. Now it's correct, with the currency symbol. So that's pretty much done. That's really the example I'd like to show you today. So just to recap, if we go back on our screen flow, what I did first, I just added the Avonni Data Table, basically setting up a basic Data Table querying an object and then selecting the fields I'd like to display on the Data Table, fine-tuning the fields with linkify, with some other options. And then what I did, I dragged this Section element at the top with columns, and inside each column I dragged the Avonni Metric. On the Avonni Metric, it's really important to remember that you need to set the value to the query, do the query based on the object you'd like to query, the field, and use the aggregate function. And what I did, it's really important, I need to dynamically filter this query based on this, because I need to consider the selection made on the Data Table. So again, filters: query selected accounts. If we go back on the formula syntax, it's like the WHERE on my SQL query, so WHERE ID IN, and then it's the dynamic attribute of the Data Table, selected row key value comma separated. That's it. And then feel free to adapt the formula for really your specific use case. The goal is really to show you the basics and the logic behind that, if you'd like to make a Metric component reactive to another component using this kind of formula text. It's extremely powerful, so you can really bring more visual stuff and functional stuff for your users using this kind of example, because they can interact with multiple components inside the screen flow, which is really nice. If you have any comment, please let me know in the comment section below, and happy building using the components for flows. Bye-bye.
Create a Text formula resource that builds an ID IN (...) clause from the Data Table attribute selected row key value comma separated, and select that formula as the Avonni Metric filter.
In the Avonni Metric, set the value to a query on the object, pick the field (Annual Revenue) and the aggregate function Sum, then filter it with the selection formula.
Query Opportunity, Opportunity ID with Count, filtered by a formula with AccountId IN the selected row key value comma separated and StageName NOT IN Closed Won and Closed Lost.
Browse the whole library, filtered by where it runs and what you want to build.
All video tutorials