Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
SBrown_Murphy
Frequent Visitor

Looking for the Power BI API for MQuery

When administering a Power BI enviorment were the reports source their data from on-prem SQL databases I've found it is hard match a problem SQL query I see in the database with the symantic model that is running it.  I'd like to use a Power BI API to pull the MQuery's from all the symantic models in all the workspaces on the tenant.  I've done this using other APIs to create SQL inventory tables of the workspaces, datasets, and other things.  I'd like to do the same with the MQuery's now.

 

The only way I was able to find an API call that might work was using an AI search, I found this: 

"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/queries"
Running it just gives this error "No HTTP resource was found that matches the request URI"
 
My questions are, do I have the right API URL?  Is there a way to do this?  If this is not the right API what is the right one?   
1 ACCEPTED SOLUTION

How do you plan to authenticate?  Did you register an app in AD with the required scope?

 

$requestBody = @"
{ "queries": [{ "query": "EVALUATE TOPN(10,Dates,[Date])"}]
 ,"serializerSettings":{"includeNulls":true}
}
"@
Login-PowerBI
$requestUrl = "datasets/xxx/executeQueries"
$result = Invoke-PowerBIRestMethod -Method Post -Url $requestUrl -Body $requestBody
$parsed = $result | ConvertFrom-Json

 

 

Here is a script with manual authentication. 

View solution in original post

6 REPLIES 6

Thank you for this suggestion but this is not working for me either. It looks like there is a function that is supposed to return the DAX Query but it errors out too. 'https://api.powerbi.com/v1.0/myorg/datasets/{dataset_ID}/executeQueries' (400): Bad Request I tried calling that API URL from the PowerShell script and got the same error. What I'm really looking for is an API URL that will work so it can be added to my PowerShell scripts.

How do you plan to authenticate?  Did you register an app in AD with the required scope?

 

$requestBody = @"
{ "queries": [{ "query": "EVALUATE TOPN(10,Dates,[Date])"}]
 ,"serializerSettings":{"includeNulls":true}
}
"@
Login-PowerBI
$requestUrl = "datasets/xxx/executeQueries"
$result = Invoke-PowerBIRestMethod -Method Post -Url $requestUrl -Body $requestBody
$parsed = $result | ConvertFrom-Json

 

 

Here is a script with manual authentication. 

"queries": [{ "query": "EVALUATE TOPN(10,Dates,[Date])"}]

What is this sction of the script for?

That's an example of a DAX query.  In your case you could use

 

EVALUATE INFO.PARTITIONS()

If you want all M Queries you would have to repeat the process with INFO.EXPRESSIONS()

 

 

 

Alternatively you could treat your semantic model as a SSAS endpoint and run the DMV queries directly.

 

Invoke-ASCmd -Server "powerbi://api.powerbi.com/v1.0/myorg/<workspace>" -Database "<semantic model>" -Query "select * from `$SYSTEM.TMSCHEMA_PARTITIONS" | Out-File -FilePath c:\users\xxx\Downloads\dmv.xml

 

In the scripts I've written up to this point I've used this to connect. 

 

Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId -Credential $PbiCredential
 
I have a service pricible that has Admin rights (the same as I have).  This makes it easy to automate the script to run from the SQL server were the data is loaded. 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Solution Authors