Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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:
Solved! Go to 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.
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.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 53 | |
| 23 | |
| 12 | |
| 11 | |
| 11 |