Custom SQL Dashboard Digest
Runs a custom aggregate SQL query (COUNT, SUM, AVG) across multiple tables, formats the results into a styled HTML email, and sends a daily executive digest.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
FlowLibs - Custom SQL Dashboard Digest is a scheduled Power Automate Cloud Flow that executes a fully customizable aggregate SQL query (COUNT, SUM, AVG, etc.) against a SQL Server database, formats the results into a professionally styled HTML email with a gradient header, data table, and footer, and delivers it as a daily executive digest to a configurable recipient list.
Key Value: Unlike the simpler "Get Rows" action, this flow uses ExecutePassThroughNativeQuery_V2 to run raw SQL — enabling JOINs, UNION ALL, GROUP BY, and multi-table aggregations that are impossible with standard row-based connectors. The entire query is stored in an environment variable, so business users can update KPIs without editing the flow logic.
Use Case
Finance and executive teams need a daily digest of key business metrics (total orders, revenue MTD, average order value, pending orders) delivered to their inbox before business hours. IT maintains the SQL query; leadership gets a clean, branded email every morning at 7 AM ET.
Flow Architecture
Recurrence Daily Digest
RecurrenceFires daily at 7:00 AM Eastern Standard Time.
Init varSqlServer
Initialize variableLoads SQL Server hostname from the `flowlibs_SqlServerName` environment variable.
Init varSqlDatabase
Initialize variableLoads database name from the `flowlibs_SqlDatabaseName` environment variable.
Init varSqlQuery
Initialize variableLoads the full aggregate SQL query from the `flowlibs_DashboardDigestSqlQuery` environment variable.
Init varDigestRecipient
Initialize variableLoads recipient email from the `flowlibs_DigestRecipientEmail` environment variable. Steps 2-5 run in parallel.
Run Dashboard Query
ExecutePassThroughNativeQuery_V2 (SQL Server)Runs the custom SQL against the configured server/database. Expects result columns: `MetricName`, `MetricValue`, `MetricDetail`.
Select HTML Table Rows
SelectMaps each result row into a styled `<tr>` with three `<td>` cells (Metric, Value, Detail) using the object-wrapped Select pattern.
Compose HTML Email Body
ComposeBuilds the complete HTML email: gradient header (blue `#0078d4`), data table with styled header row, and footer with flow attribution. Uses `string()` + `replace()` to unwrap the Select output into clean HTML.
Send Digest Email
SendEmailV2 (Office 365 Outlook)Delivers the styled HTML to the configured recipient with a dynamic subject line including today's date.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SqlServerName | String | <configure> | SQL Server hostname. Set to the fully qualified hostname of your SQL Server instance (configured per tenant). |
| flowlibs_SqlDatabaseName | String | <configure> | Target database name on the SQL Server instance (configured per tenant). |
| flowlibs_DashboardDigestSqlQuery | String | SELECT 'Total Orders' AS MetricName, CAST(COUNT(*) AS VARCHAR) AS MetricValue, 'All orders in system' AS MetricDetail FROM Orders UNION ALL ... | The full aggregate SQL query. Must return exactly three columns: MetricName, MetricValue, MetricDetail. Use UNION ALL to combine multiple metric queries. |
| flowlibs_DigestRecipientEmail | String | <configure> | Email address (or semicolon-separated list) that receives the daily digest. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SQL Server | shared_sql | ExecutePassThroughNativeQuery_V2 (runs the custom aggregate SQL) |
| Office 365 Outlook | shared_office365 | SendEmailV2 (delivers the styled HTML digest) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Change the SQL query
- Update the flowlibs_DashboardDigestSqlQuery environment variable value. The query must return exactly three columns: MetricName (VARCHAR), MetricValue (VARCHAR), and MetricDetail (VARCHAR). Use UNION ALL to combine multiple metric queries.
- Change the schedule
- Edit the Recurrence trigger — modify hours, minutes, frequency, or timeZone to adjust delivery time.
- Change the recipient
- Update flowlibs_DigestRecipientEmail. For multiple recipients, use a semicolon-separated list.
- Point to a different database
- Update flowlibs_SqlServerName and flowlibs_SqlDatabaseName environment variables.
- Customize email styling
- Edit the Compose action HTML template — the gradient colors, table styles, and footer text are all inline CSS.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01SQL query execution
Passed to the `query/query` parameter of `ExecutePassThroughNativeQuery_V2`.
EXPR.02Result set access
The V2 query returns results nested under `resultsets.Table1`.
EXPR.03Select HTML row template
Object-wrapped Select pattern — each result row is mapped to an HTML `<tr>`.
EXPR.04HTML unwrap
Strips the object-wrapper JSON noise so only the concatenated `<tr>` rows remain.
EXPR.05Dynamic subject
Appends today's UTC date to the email subject.
EXPR.06Timestamp in header
Rendered into the email header for the run date and time.
Customize & download
Generate a ready-to-import copy of this solution with your environment-variable values baked in — available on Base, Pro, or Team.
Upgrade to customize
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.