SQL Data Transform and Export to Excel
Manually triggered flow that uses Power Query to transform and reshape SQL data (rename columns, filter, pivot), then exports the result to an Excel file on SharePoint.
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 - SQL Data Transform and Export to Excel is a manually triggered cloud flow that executes a SQL Server transform query (supporting column renames, filters, and aggregations via native T-SQL), then exports the results to both a CSV file on SharePoint and structured rows in an Excel Online workbook. This flow demonstrates a no-code ETL pattern for extracting, transforming, and loading SQL data into business-friendly formats.
Trigger Type: Manual (Instant — button trigger with optional text input)
Use Case
Finance and Operations teams often need to pull transformed data from SQL Server databases — applying column renames, filters, and aggregations — and deliver the results in Excel format for reporting, auditing, or downstream analysis. This flow automates that entire pipeline: run a T-SQL transform query, generate a CSV file on SharePoint for archival, and write each row into a structured Excel table for interactive use.
When to Use: Scheduled or ad-hoc data exports, report generation, SQL-to-Excel ETL pipelines, audit snapshots.
The flow is ideal for teams that:
- Finance teams running ad-hoc or scheduled data exports
- Operations teams generating audit snapshots from SQL data
- Report generation pipelines that need a CSV archive plus an interactive Excel table
- SQL-to-Excel ETL workflows that apply T-SQL transforms (renames, filters, aggregations)
Flow Architecture
Manually trigger a flow
Manual triggerInstant button trigger that accepts an optional Export_Description text input used to tag the export run.
Init_varSqlServer
InitializeVariableSets the SQL Server name from environment variable flowlibs_SqlServerName. Runs in parallel with the other Init actions.
Init_varSqlDatabase
InitializeVariableSets the database name from environment variable flowlibs_SqlDatabaseName. Runs in parallel with the other Init actions.
Init_varSharePointSiteUrl
InitializeVariableSets the SharePoint site URL from environment variable flowlibs_SharePointSiteURL. Runs in parallel with the other Init actions.
Init_varTransformQuery
InitializeVariableSets the T-SQL transform query from environment variable flowlibs_CF295_TransformQuery. Runs in parallel with the other Init actions.
Init_varExcelFilePath
InitializeVariableSets the Excel file path from environment variable flowlibs_CF295_ExcelFilePath. Runs in parallel with the other Init actions.
Init_varExcelTableName
InitializeVariableSets the Excel table name from environment variable flowlibs_CF295_ExcelTableName. Runs in parallel with the other Init actions.
Execute_SQL_Transform_Query
SQL Server — Execute a SQL query (V2)Executes the configured T-SQL transform query against the SQL database using ExecutePassThroughNativeQuery.
Select_Normalized_Columns
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SqlServerName | String | <configure> | SQL Server hostname or IP address that hosts the source database. Set per environment. |
| flowlibs_SqlDatabaseName | String | <configure> | Name of the target SQL database the transform query runs against. Set per environment. |
| flowlibs_SharePointSiteURL | String | <configure> | SharePoint site URL where the CSV export file is created (e.g. https://your-tenant.sharepoint.com/sites/YourSite). |
| flowlibs_CF295_TransformQuery | String | SELECT * FROM SampleTable | T-SQL query that returns the flat result set to export. Apply renames, filters, and aggregations here — column names from the query become the fields used by the Select, CSV, and Excel actions. |
| flowlibs_CF295_ExcelFilePath | String | /Shared Documents/Exports/SQLExport.xlsx | Path to the destination Excel workbook within the configured SharePoint site. The workbook and table must already exist. |
| flowlibs_CF295_ExcelTableName | String | SQLExportTable | Name of the table inside the Excel workbook that rows are appended to via Add_Row_to_Excel. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SQL Server | shared_sql | ExecutePassThroughNativeQuery (Execute_SQL_Transform_Query) |
| Excel Online (Business) | shared_excelonlinebusiness | AddRowV2 (Add_Row_to_Excel (inside For_Each_Row_Write_to_Excel)) |
| SharePoint | shared_sharepointonline | CreateFile (Create_CSV_File_on_SharePoint) |
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.
- Changing the SQL Query
- Update the flowlibs_CF295_TransformQuery environment variable with your T-SQL. The query should return a flat result set — column names from the query become the fields available in downstream actions (Select, CSV, Excel).
- Changing the Export Location
- Update flowlibs_CF295_ExcelFilePath to point to a different SharePoint document library path. Ensure the Excel workbook and table already exist at that path before running the flow.
- Adding Email Notification
- Add a Send an email (V2) action after Compose_Export_Summary using the Office 365 Outlook connector. Reference the summary output for row count and file path details.
- Modifying Column Mapping
- Edit the Select_Normalized_Columns action to change how SQL result columns map to your Excel table columns. The from field references the SQL output; the key/value pairs define the normalized column names.
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.01Row Count
Counts the rows returned by the SQL transform query for the export summary.
EXPR.02CSV Header Row (from Select output)
Builds the CSV header row by joining the keys of the first normalized result with commas.
EXPR.03Timestamp for File Naming
Produces a sortable timestamp suffix used when naming the exported CSV.
EXPR.04Export Summary Object
Builds the JSON summary object emitted by Compose_Export_Summary (rowCount, filePath, exportedAt).
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.