Flow Complexity Score Calculator
Scheduled flow analyzes flow definitions via Power Automate Management, counting total actions, nesting depth, parallel branches, and connector count per flow. Writes a complexity score to Dataverse and emails a monthly report flagging flows exceeding a complexity threshold for architectural review.
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
The Flow Complexity Score Calculator is a scheduled monthly flow that analyzes every cloud flow in the target Power Platform environment. It retrieves each flow's full definition via the Power Automate Management connector, computes four structural metrics (total actions, nesting depth, parallel branches, and connector count), and combines them into a weighted complexity score. Each score is upserted to a Dataverse tracking table for historical trending. Flows exceeding a configurable complexity threshold are flagged in a CSS-styled HTML email report sent to the admin team with refactoring recommendations.
Use Case
IT admins and COE leads need visibility into which flows are becoming architecturally complex — too many actions, deeply nested conditions, excessive parallel branches, or too many connector types. Complex flows are harder to maintain, debug, and hand off. This flow provides a monthly automated audit that surfaces high-complexity flows before they become production risks.
Flow Architecture
Recurrence Monthly
RecurrenceFires on the 1st of each month at 8:00 AM UTC.
6x Parallel Initialize Variable
Initialize variable (parallel block of 6)Binds 4 environment variables (target environment, admin email, complexity table name, complexity threshold) and initializes 2 working variables (HTML accumulator, high-complexity counter).
List All Flows
ListFlowsInEnvironment_V2 (Power Automate Management)Retrieves all cloud flows in the target Power Platform environment.
For Each Flow
Apply to eachFor each flow returned by List All Flows, performs the following nested actions: Get Flow Definition (AdminGetFlow) to retrieve the full flow JSON; a 4-way parallel Compose block that computes Total Actions (count of "type":), Nesting Depth (count of nested "actions":), Parallel Branches (count of "runAfter":{}), and Connector Count (count of "id": in connectionReferences) using string-splitting heuristics; Compute Complexity Score = totalActions + (nestingDepth x 5) + (parallelBranches x 3) + (connectorCount x 2); Check Existing Record via Dataverse ListRecords filtered by flow GUID; Upsert (if record exists then UpdateRecord, else CreateRecord) with all metrics plus a timestamp; Threshold Check that appends an HTML table row and increments the high-complexity counter when the score exceeds the threshold.
If Any High Complexity
If conditionChecks whether the high-complexity counter is greater than 0 after the per-flow loop completes.
- Compose Report — Builds a CSS-styled HTML email with a gradient header, stat badge, data table (flow name, score, actions, nesting, parallel, connectors, creator), and a recommendations section.
- — Outlook SendEmailV2 sends the assembled HTML report to the admin notification address.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_TargetEnvironmentName | String | <configure> | Power Platform environment ID (GUID) for flow enumeration. Set per tenant. |
| flowlibs_AdminNotificationEmail | String | <configure> | Recipient address for the monthly complexity report (e.g. alerts@yourcompany.com). Set per tenant. |
| flowlibs_ComplexityScoreTable | String | flowlibs_flowcomplexityscores | Dataverse entity set (plural logical) name for storing complexity score records. |
| flowlibs_ComplexityThreshold | String | 50 | Score above which flows are flagged in the monthly report. Lower values flag more flows. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Power Automate Management | shared_flowmanagement | ListFlowsInEnvironment_V2 (list all flows in the target environment) AdminGetFlow (retrieve full flow definition JSON) |
| Microsoft Dataverse | shared_commondataserviceforapps | ListRecords (check existing complexity record by flow GUID) CreateRecord UpdateRecord |
| Office 365 Outlook | shared_office365 | SendEmailV2 (monthly complexity report) |
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.
- Activate the flow
- Open in the designer, authorize the 3 connections, set environment variable current values, then turn the flow On.
- Adjust the threshold
- Change the flowlibs_ComplexityThreshold env var value (default 50). Lower values flag more flows; higher values flag only the most complex.
- Change the scoring weights
- Edit the Compute_Complexity_Score Compose expression to adjust multipliers (nesting x5, parallel x3, connectors x2) to better match your team's notion of complexity.
- Add email recipients
- Update flowlibs_AdminNotificationEmail to a distribution list, or modify the Send Email action to add CC / BCC recipients.
- Change frequency
- Modify the Recurrence trigger — switch from Monthly to Weekly (or another cadence) for more frequent audits.
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.01Total Actions
Counts action type declarations via string splitting on the serialized flow definition.
EXPR.02Nesting Depth
Counts nested action containers (subtracts 1 for the root split segment).
EXPR.03Parallel Branches
Counts empty runAfter blocks, which indicate parallel branch roots.
EXPR.04Connector Count
Counts connection reference entries in the flow definition.
EXPR.05Complexity Score
Weighted composite: totalActions + (nestingDepth x 5) + (parallelBranches x 3) + (connectorCount x 2).
EXPR.06Upsert guard
Determines whether to update an existing Dataverse record or create a new one.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.