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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
BrandedSaiyan
Advocate II
Advocate II

Possible to Query Keywords in SQL Statement Datasource Using API?

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.


BrandedSaiyan_0-1659032768129.png

 

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.

BrandedSaiyan_1-1659033179852.png

 


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

 

2 ACCEPTED SOLUTIONS

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.

View solution in original post

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

View solution in original post

14 REPLIES 14
lbendlin
Super User
Super User

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!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Top Kudoed Authors