Opportunity Win/Loss Analysis Extractor
Salesforce action: ExecuteSOQLQuery. Monthly flow runs SOQL to extract all closed-won and closed-lost opportunities, calculates win rate by rep/region/product, writes analysis to Excel, and emails the leadership team.
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
A scheduled Power Automate cloud flow that extracts closed-won and closed-lost opportunities from Salesforce on the 1st of every month, appends each opportunity as a row in a SharePoint-hosted Excel workbook, and emails a summary scorecard (win count, loss count, total won/lost amount, win rate %) to a leadership distribution list.
The flow is designed as a FlowLibs reference pattern demonstrating:
- Recurrence trigger on a monthly calendar schedule - Dynamic SOQL construction from an environment variable - Aggregation inside a Foreach using conditional IncrementVariable actions - Connector-to-connector bridge (Salesforce -> Excel Online Business -> Outlook) - Full parameterization via Dataverse environment variables for ALM portability
Use Case
Revenue Operations and Sales Leadership teams typically manually export Salesforce Opportunity reports at month-end for pipeline reviews. This flow automates the extraction and scorecarding so leadership gets a month-over-month Excel record plus an at-a-glance HTML summary email with zero manual effort. The Excel workbook becomes a historical ledger that Power BI can point at for trend analysis.
The flow is ideal for teams that:
- Revenue Operations teams automating month-end Salesforce opportunity reporting
- Sales leadership needing recurring win/loss scorecards without manual exports
- Finance and executives tracking month-over-month win rate and closed-revenue trends
- Teams building a historical Excel ledger to feed Power BI trend analysis
Flow Architecture
Monthly_Win_Loss_Extract
RecurrenceRuns on the 1st of every month at 06:00 Eastern Standard Time. Frequency = Month, interval = 1, schedule: monthDays [1], hours [6], minutes [0].
Initialize_SharePointSiteUrl
Initialize variableString variable seeded from the flowlibs_SharePointSiteURL environment variable.
Initialize_DriveId
Initialize variableString variable seeded from the flowlibs_WinLossExcelDriveId environment variable.
Initialize_FilePath
Initialize variableString variable seeded from the flowlibs_WinLossExcelFilePath environment variable.
Initialize_TableName
Initialize variableString variable seeded from the flowlibs_WinLossExcelTableName environment variable.
Initialize_LookbackMonths
Initialize variableString variable seeded from the flowlibs_WinLossLookbackMonths environment variable; controls the LAST_N_MONTHS window.
Initialize_Recipients
Initialize variableString variable seeded from the flowlibs_LeadershipEmailRecipients environment variable (comma-separated leadership distribution list).
Initialize_WonCount
Initialize variableInteger variable seeded to 0 to count Closed Won opportunities.
Initialize_LostCount
Initialize variableInteger variable seeded to 0 to count Closed Lost opportunities.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SharePointSiteURL | String | <configure> | SharePoint site collection URL used by Excel Online Business actions (e.g. https://your-tenant.sharepoint.com/sites/RevOps). |
| flowlibs_WinLossExcelDriveId | String | <configure> | Graph drive ID (starts with b!...) of the document library containing the Win/Loss Excel workbook. |
| flowlibs_WinLossExcelFilePath | String | <configure> | Drive-relative path to the Win/Loss Excel workbook (e.g. /Shared Documents/Sales/WinLoss.xlsx). |
| flowlibs_WinLossExcelTableName | String | <configure> | Name of the Excel table where opportunity rows are appended; columns must be Id, Name, StageName, Owner, Amount, CloseDate, Type, LeadSource. |
| flowlibs_WinLossLookbackMonths | String | 1 | Number of months back to query closed opportunities, used in LAST_N_MONTHS:n. Set to 3 for a rolling quarter or 12 for annual. |
| flowlibs_LeadershipEmailRecipients | String | alerts@yourcompany.com | Comma-separated recipient list for the monthly summary email. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Salesforce | shared_salesforce | ExecuteSOQLQuery |
| Excel Online (Business) | shared_excelonlinebusiness | AddRowV2 |
| Office 365 Outlook | shared_office365 | SendEmailV2 |
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 schedule
- Edit the Monthly_Win_Loss_Extract Recurrence trigger to change monthDays, hours, or timeZone. The default runs on the 1st of each month at 06:00 ET so downstream consumers have fresh data before the business day starts.
- Change the lookback window
- Update the flowlibs_WinLossLookbackMonths env variable (no flow edit required). Set to 3 for a rolling quarterly report or 12 for an annual comparison.
- Change recipients
- Update the flowlibs_LeadershipEmailRecipients env variable with a new comma-separated address list.
- Change the Excel destination
- Update the four workbook env variables (flowlibs_SharePointSiteURL, flowlibs_WinLossExcelDriveId, flowlibs_WinLossExcelFilePath, flowlibs_WinLossExcelTableName). The table columns must remain Id, Name, StageName, Owner, Amount, CloseDate, Type, LeadSource, or the Add_Opportunity_Row_To_Excel parameters must be adjusted to match.
- Add fields to SOQL
- Extend the SELECT clause in Build_SOQL_Query and add corresponding item/* parameters to Add_Opportunity_Row_To_Excel. Remember to add the matching column to the Excel table first.
- Change win stage definition
- Edit the equals expression in Determine_Won_Or_Lost if your org uses a stage name other than 'Closed Won' for wins.
- Tune throughput
- Foreach is set to concurrency.repetitions = 1 for deterministic ordering and Excel safety. Increase to 8-16 if your workbook can tolerate parallel row inserts and runtime is a concern.
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.01SOQL construction
Builds the SOQL string by concatenating the lookback months env variable into the LAST_N_MONTHS clause.
EXPR.02Null-safe amount increment
Avoids runtime errors when an opportunity's Amount is null by substituting 0.
EXPR.03Divide-by-zero-safe win rate
Returns '0.0' when no opportunities were processed; otherwise returns the win rate percentage as a string.
EXPR.04Nested Owner.Name access
Reads the Owner display name from the nested Owner object returned by SOQL.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.