March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello Power BI Community,
I recently gained access to the Power BI REST API. I was hoping there would be a way to do a keyword search on the SQL Statement that is part of part of a SQL Server datasource for a dataset for a report. See screen shot below for where I am refering to.
Our issue is that instead of using views or stored procedures in our SQL statements, 90% of our reports are using inline SQL code. It's almost impossible to do a dependecy check or impact analysis with our reports written this way and I was hoping the REST API would allow us to do an organization wide search of the SQL statement in all datasources across all datasets so we could search for specific tables and objects.
Using the Datasets - Get Datasources endpoint only gets me the datasource type and connectiondetails (being the server and database) for a given datasource, but not the sql statement.
Is there any way that I can query for the SQL statement?
Edit: Adding @Greg_Deckler since his expertise has helped me in the past 🙂
Thank you
Solved! Go to Solution.
You have to run it against each dataset (that you have access to) separately. However you can sort of automate that by running the queries from PowerShell.
Invoke-ASCmd -Server "powerbi://api.powerbi.com/v1.0/myorg/<workspace name here>" -Database "<dataset name here>" -Query "select * from `$SYSTEM.TMSCHEMA_PARTITIONS" | Out-File -FilePath c:\users\xxx\Downloads\dmv.xml
You're in for a treat. You will want to learn about XMLA endpoints, and DMX queries. You can run these against all your datasets and extract the complete M code for all connections (including the embedded SQL).
NOTE: This is only valid for Import Mode connections. For Direct Query you have no control over, or visibility of the queries that are generated on the fly for each visual.
Thank you, do you have any helpful links or resources you'd reccomend?
There's DAX Studio , but beyond that the air is pretty thin. Mostly trial and error.
I have DAX studio, but I'm unfamilar with any function or code that extracts the M code. I'll do some digging, was just hoping to be pointed in the right direction. Thanks again.
In DAX Studio connect to your dataset (local or in service)
Run two queries (individually)
select * from $SYSTEM.TMSCHEMA_PARTITIONS
select * from $SYSTEM.TMSCHEMA_EXPRESSIONS
Grab the QueryDefinition column from the first and the Expression column from the second
Rinse and repeat for all your datasets.
Thank you! Do you know if I'm able to run this against a shared power bi dataset? Or if it can be ran more in bulk rather than foiir just one dataset at a time? Much appreciated.
You have to run it against each dataset (that you have access to) separately. However you can sort of automate that by running the queries from PowerShell.
Circling back here. I've been unable to find a way to run these queries from powershell. Any help would be greatly appreciated.
Thanks!
Invoke-ASCmd -Server "powerbi://api.powerbi.com/v1.0/myorg/<workspace name here>" -Database "<dataset name here>" -Query "select * from `$SYSTEM.TMSCHEMA_PARTITIONS" | Out-File -FilePath c:\users\xxx\Downloads\dmv.xml
This ended up working great!
Note that there is a subtle difference between "PARTITIONS" and "EXPRESSIONS".
Thanks for pointing this out. I'm noticing for a report I'm currently working on I have 3 SQL Server datasources showing under PARTITIONS and 1 SQL Server source showing under EXPRESSIONS. I'm not able to determine the difference or why one shows under expressions. Any further insight is appreciated.
Both are queries. Partitions are loaded into the Vertipaq engine. Expressions are not loaded into the engine but may participate in the data pull, especially when other queries depend on them (even when you explicitly state you don't want to refresh them !).
You can tell by the italicization of the query name in Power Query.
I really appreciate all your help, going to give this a try and get back to you! Thank you!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
6 | |
3 | |
2 | |
2 | |
2 |