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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sdegroot
Helper I
Helper I

Is there a way to view all SQL tables used in our organization's Power BI workspaces?

Hi there, our organization has about 25 Power BI workspaces and 200 power BI reports. Most reports are fed using SQL and we are now looking to list all SQL tables used so that the correct report writers are notified of any changes. Any suggestions on doing this?
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @sdegroot 

You can try using Power BI REST APIs to get a list of datasources for a specified dataset.

Datasets - Get Datasources (Power BI Power BI REST APIs)

Datasets - Get Datasources In Group (Power BI Power BI REST APIs)

 

And get a list of gateway datasources for a specified dataset.

Datasets - Get Gateway Datasources (Power BI Power BI REST APIs) 

Datasets - Get Gateway Datasources In Group (Power BI Power BI REST APIs)

 

Hope this helps.

Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

8 REPLIES 8
sdegroot
Helper I
Helper I

Thanks! This seems to only show the gateway names a reporter chooses for the published pbix, however we are looking for the SQL table names. 

This will only give you the database and server, not the tables. I don't see anything in the API or PowerShell that will drill down that far.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

These days, you can use https://learn.microsoft.com/en-us/rest/api/power-bi/admin/workspace-info-post-workspace-info with the parameter "datasetExpressions" set to True. The name of the schema and table will be in the expression. Here are all the params I used:

params = {
            "lineage": True,
            "datasourceDetails": True,
            "datasetSchema": True,
            "datasetExpressions": True,
            "getArtifactUsers": True,
        }
NOTE that you must enable a couple settings in PowerBI tenant settings (app.powerbi.com -> Settings -> Admin portal -> Tenant settings; section "Admin API Settings") to make this work:
- Service principals can access read-only admin APIs
Enhance admin APIs responses with detailed metadataEnhance admin APIs responses with DAX and mashup expressions

do you have more details how to do this? this is exactly what I am looking for

Yes, what do you need to know? I can send you some example Python code if that helps.

did you run this in powershell or via Power BI rest api url?

 

also it gave you a full list of all tables being used in ALL workspaces?

 

thanks in advance!

powerbihelp87_0-1741197445544.png

 

I use PowerBI REST API through Python. Here's some sample code, using the `dlt` data ingestion library:

 

from collections.abc import Generator
from time import sleep
from typing import Any

from azure.identity import ClientSecretCredential
import dlt
from dlt.common import logger as dlt_logger
from dlt.sources.helpers.rest_client import RESTClient
from dlt.sources.helpers.rest_client.auth import OAuth2AuthBase
from dlt.sources.helpers.rest_client.paginators import SinglePagePaginator


class PowerBIOauthClientCredentials(OAuth2AuthBase):
    def __init__(self, tenant_id: str, client_id: str, client_secret: str):
        """PowerBI OAuth2 client credentials authentication.

        Args:
            tenant_id (str): The Azure tenant ID.
            client_id (str): The client ID of the service principal app.
            client_secret (str): The client secret of the service principal app.
        """
        super().__init__()
        self.access_token = self._get_token(tenant_id, client_id, client_secret)

    @staticmethod
    def _get_token(tenant_id: str, client_id: str, client_secret: str) -> str:
        scope = "https://analysis.windows.net/powerbi/api/.default"
        client_secret_credential_class = ClientSecretCredential(
            tenant_id=tenant_id, client_id=client_id, client_secret=client_secret
        )
        return client_secret_credential_class.get_token(scope).token


client = RESTClient(
    base_url="https://api.powerbi.com/v1.0/myorg",
    auth=PowerBIOauthClientCredentials(
        tenant_id=tenant_id,
        client_id=client_id,
        client_secret=client_secret,
    ),
    paginator=SinglePagePaginator(),
)


def workspaces() -> Generator[list[dict[str, Any]], None, None]:
    endpoint = "groups"
    yield client.get(endpoint).json()["value"]


def workspaces_lineage(
    workspaces: list[dict[str, Any]],
) -> Generator[list[dict[str, Any]], None, None]:
    workspace_ids = [workspace["id"] for workspace in workspaces]
    request_lineage_endpoint = "admin/workspaces/getInfo"
    params = {
        "lineage": True,
        "datasourceDetails": True,
        "datasetSchema": True,
        "datasetExpressions": True,
        "getArtifactUsers": True,
    }
    body = {"workspaces": workspace_ids}

    # Request a workspace lineage scan and await scan completion.
    response = client.post(request_lineage_endpoint, params=params, json=body)
    scan_id = response.json()["id"]
    scan_status = None
    dlt_logger.info("Waiting for scan to complete...")
    while scan_status != "Succeeded":
        scan_status_endpoint = f"admin/workspaces/scanStatus/{scan_id}"
        scan_status = client.get(scan_status_endpoint).json()["status"]
        sleep(0.1)

    # Get the scan result.
    scan_result_endpoint = f"admin/workspaces/scanResult/{scan_id}"
    response = client.get(scan_result_endpoint)
    lineage = response.json()

    yield lineage

 

 

The process is this:
1. Get a list of workspaces via a GET request to https://api.powerbi.com/v1.0/myorg/groups
2. Perform a POST request to 
https://api.powerbi.com/v1.0/myorg/admin/workspaces/getInfo to initialize a lineage scan
3. Monitor scan status by periodically sending a GET request to https://api.powerbi.com/v1.0/myorg/
admin/workspaces/scanStatus/{scan_id}
4. Once the scan is complete, send a GET request to https://api.powerbi.com/v1.0/myorg/
admin/workspaces/scanResult to retrieve the lineage JSON.

From there, if you have the PowerBI settings I mentioned previously and corrent accesses configured, you will have the raw queries in the resonse. They look something like this:

"expression": "let\n    Source = PostgreSQL.Database(\"some-addr.us-east-2.aws.neon.tech\", \"mydb\"),\n    my_schema_my_table = Source{[Schema=\"my_schema\",Item=\"my_db\"]}[Data]\nin\n    my_schema_my_table"

 

v-jingzhang
Community Support
Community Support

Hi @sdegroot 

You can try using Power BI REST APIs to get a list of datasources for a specified dataset.

Datasets - Get Datasources (Power BI Power BI REST APIs)

Datasets - Get Datasources In Group (Power BI Power BI REST APIs)

 

And get a list of gateway datasources for a specified dataset.

Datasets - Get Gateway Datasources (Power BI Power BI REST APIs) 

Datasets - Get Gateway Datasources In Group (Power BI Power BI REST APIs)

 

Hope this helps.

Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors