This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
Power Query has long been at the center of data preparation across Microsoft products—from Excel and Power BI to Dataflows and Fabric. We're introducing a major evolution: the ability to execute Power Query programmatically through a public API.
This capability turns Power Query into a programmable data transformation engine that can be invoked on demand through a REST API from notebooks, pipelines, and applications. Whether you're orchestrating data pipelines, building custom data apps, or integrating Power Query into larger workflows, this API unlocks new flexibility and automation.
Power Query provides both ease of use and expressive transformation capabilities through the M language. Historically, query evaluation has been tied to dataflow refreshes or interactive tools. Programmatic query evaluation changes this model completely.
It enables:
Power Query is now a first-class compute engine within Fabric.
While Spark notebooks are a canonical example, programmatic execution is available across multiple Fabric surfaces:
Invoke Power Query and receive results as Spark or Pandas DataFrames.
Trigger transformations from any HTTP client using a public, documented API.
Integrate Power Query steps into orchestrated workflows.
Evaluate Power Query scripts against on-premises or private network sources.
The Execute Query API evaluates a Power Query M script and returns results as an Apache Arrow stream.
az account get-access-token \
--resource https://analysis.windows.net/powerbi/api/ \
--query accessToken \
-o tsv
token = notebookutils.credentials.getToken(
"https://analysis.windows.net/powerbi/api/"
)
POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/dataflows/{dataflowId}/executeQuery
Headers:
Authorization: Bearer <token>
Content-Type: application/json
{
"queryName": "MyQuery",
"customMashupDocument": "<M script here>"
}
Notes:
workspaceId and dataflowId are specified in the URL, not the request body.customMashupDocument is optional. If omitted, the API executes the query named by queryName from the dataflow's existing queries—so the query must already exist in the dataflow.with pa.ipc.open_stream(response.raw) as reader:
df = reader.read_pandas()
import requests
import pyarrow as pa
workspace_id = "00000000-0000-0000-0000-000000000000"
artifact_id = "11111111-1111-1111-1111-111111111111"
fabric_token = notebookutils.credentials.getToken(
"https://analysis.windows.net/powerbi/api/"
)
headers = {
"Authorization": f"Bearer {fabric_token}",
"Content-Type": "application/json",
}
url = (
f"https://api.fabric.microsoft.com/v1/"
f"workspaces/{workspace_id}/dataflows/{artifact_id}/executeQuery"
)
request_body = {
"queryName": "Monthly2020Trends",
"customMashupDocument": """
section Section1;
shared Monthly2020Trends =
let
Source = Lakehouse.Contents(null),
Navigation = Source{[workspaceId = "00000000-0000-0000-0000-000000000000"]}[Data],
LakehouseData = Navigation{[lakehouseId = "33333333-3333-3333-3333-333333333333"]}[Data],
TaxiData = LakehouseData{[Id = "green_tripdata_2020", ItemKind = "Table"]}[Data],
AddMonth =
Table.AddColumn(
TaxiData,
"Month",
each Date.Month(DateTime.Date([lpep_pickup_datetime])),
Int64.Type
),
MonthlyStats =
Table.Group(
AddMonth,
{"Month"},
{
{"TripCount", each Table.RowCount(_), Int64.Type},
{"AvgFare", each List.Average([fare_amount]), type number}
}
),
Sorted = Table.Sort(MonthlyStats, {{"Month", Order.Ascending}})
in
Sorted;
"""
}
response = requests.post(url, headers=headers, json=request_body, stream=True)
print(response.status_code)
print(response.headers)
if response.status_code != 200:
print(response.content)
else:
with pa.ipc.open_stream(response.raw) as reader:
data_frame = reader.read_pandas()
display(data_frame)
customMashupDocument. However, if a query defined in the dataflow itself uses native queries, it can be executed successfully.Execute Query API usage shows up in the capacity metrics app as the operation "Dataflows Gen2 Run Query API" billed using the same meter as Dataflow Gen2 refreshes. The consumption is based on the duration of the query.
For detailed pricing information, see Dataflow Gen2 pricing and billing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.