Monthly Data Rollup Trigger
On the 1st of each month, executes a stored procedure that aggregates the prior month's transactional data into a summary table. Demonstrates calling pre-built SQL logic from Power Automate.
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
On the 1st of each month, this flow executes a stored procedure that aggregates the prior month's transactional data into a summary table, then verifies the rollup and sends a styled HTML notification email with the results. Demonstrates calling pre-built SQL logic from Power Automate — separation of concerns between database logic and orchestration.
Use Case
Finance and IT teams often need to aggregate transactional data at month-end for reporting, dashboards, and compliance. Rather than embedding complex SQL aggregation logic directly into a Power Automate flow, this pattern calls a stored procedure that encapsulates all the rollup logic. The flow handles orchestration (scheduling, verification, notification) while the database handles computation. This keeps the flow portable across environments — only the stored procedure name and connection details need to change.
The flow is ideal for teams that:
- Finance teams running month-end aggregation jobs for reporting and compliance
- IT admins who want to keep heavy aggregation logic inside SQL while Power Automate handles orchestration
- Teams that need a portable rollup pattern that moves cleanly between environments by swapping env vars
Flow Architecture
Recurrence Monthly 1st
RecurrenceFires on the 1st of every month at 2:00 AM UTC. The startTime is set to 2026-05-01T02:00:00Z with a monthly interval.
Initialize SQL + Email Variables (5x Parallel)
Initialize variableFive Initialize Variable actions run in parallel after the trigger to read env vars into flow-scoped variables: varSqlServer ← flowlibs_SqlServerName, varSqlDatabase ← flowlibs_SqlDatabaseName, varStoredProcName ← flowlibs_SqlStoredProcedureName, varSummaryTable ← flowlibs_SqlSummaryTableName, varDigestRecipient ← flowlibs_DigestRecipientEmail.
Execute Stored Procedure
SQL Server — ExecutePassThroughNativeQuery_V2Builds a dynamic EXEC statement: EXEC [dbo].[usp_MonthlyDataRollup] @ReportMonth = 'YYYY-MM' where the month is calculated as the prior month using addToTime(utcNow(), -1, 'Month').
Verify Summary Table Count
SQL Server — ExecutePassThroughNativeQuery_V2Runs SELECT COUNT(*) AS RowCount, MAX(RollupDate) AS LatestRollup FROM [summary_table] WHERE FORMAT(RollupDate, 'yyyy-MM') = 'YYYY-MM' to confirm data was written.
Compose Rollup Summary
ComposeBuilds a styled HTML table with report month, stored procedure name, summary table name, rows written, latest rollup date, and execution timestamp. Uses a gradient header style consistent with FlowLibs branding.
Send Rollup Notification
Office 365 Outlook — SendEmailV2Sends the HTML summary to the digest recipient with a dynamic subject line: 'Monthly Data Rollup Complete - {Month Year}'.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SqlServerName | String | your-server.database.windows.net | Target SQL Server hostname. |
| flowlibs_SqlDatabaseName | String | FlowLibsDemoDB | Target database. |
| flowlibs_SqlStoredProcedureName | String | [dbo].[usp_MonthlyDataRollup] | Stored procedure to execute for the monthly rollup. |
| flowlibs_SqlSummaryTableName | String | [dbo].[MonthlySummary] | Table where rollup data is written and verified. |
| flowlibs_DigestRecipientEmail | String | user@contoso.com | Email recipient for the monthly rollup notification. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SQL Server | shared_sql | ExecutePassThroughNativeQuery_V2 (Execute stored procedure) ExecutePassThroughNativeQuery_V2 (Verify summary table count) |
| Office 365 Outlook | shared_office365 | SendEmailV2 (Send rollup notification email) |
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.
- Create the stored procedure in your target SQL Server database
- The flow expects a stored procedure that accepts a @ReportMonth parameter in YYYY-MM format. Example: ``sql CREATE PROCEDURE [dbo].[usp_MonthlyDataRollup] @ReportMonth NVARCHAR(7) AS BEGIN INSERT INTO [dbo].[MonthlySummary] (RollupDate, MetricName, MetricValue) SELECT CAST(@ReportMonth + '-01' AS DATE), Category, SUM(Amount) FROM [dbo].[Transactions] WHERE FORMAT(TransactionDate, 'yyyy-MM') = @ReportMonth GROUP BY Category; END
- Update environment variables
- Set your server name, database, stored procedure name, summary table, and notification email in the five flowlibs_* environment variables that ship with the solution.
- Authorize connections
- Open the flow in the designer and complete the SQL Server and Office 365 Outlook connection prompts to sign in with the accounts that should run the queries and send the digest.
- Turn on the flow
- Once env vars and connections are set, switch the flow on — it will execute on the 1st of the next month at 2:00 AM UTC.
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.01Prior month calculation
Always targets the previous month regardless of when the flow runs.
EXPR.02Dynamic EXEC statement
Builds the stored procedure call with the prior-month parameter inline.
EXPR.03Result access pattern
Navigates the ExecutePassThroughNativeQuery_V2 response structure to pull the row count.
EXPR.04Null-safe fallback
Handles cases where no data was returned by substituting 'N/A'.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.