Forum Discussion

S_Kostiantyn's avatar
S_Kostiantyn
Regular Visitor
1 year ago
Solved

How to access M queries when Power BI Admin API returns empty tables array for PbixInImportMode data

I'm using the Power BI Admin API to scan our workspaces and extract data sources and M queries from datasets. Specifically, I'm using the /v1.0/myorg/admin/workspaces/getInfo endpoint with the follo...
  • DataNinja777's avatar
    1 year ago

    Hi S_Kostiantyn ,

     

    You cannot reliably retrieve M queries from “PbixInImportMode” datasets using the Admin getInfo endpoint because it often returns empty tables arrays for import‐mode PBIX files. Instead, you can use the Metadata Scanning (Lineage) APIs that allow you to initiate and retrieve a tenant‐wide scan, returning dataset schema and M expressions for each dataset. Alternatively, if the dataset is in Premium or Premium Per User capacity, you can connect via the XMLA endpoint using a tool such as SQL Server Management Studio or Tabular Editor to inspect the Tabular Object Model and locate the M queries under each table’s partition. For example, in SSMS you can run the following query to retrieve the M expressions:

    SELECT *
    FROM $SYSTEM.TMSCHEMA_PARTITIONS
    

    The export to PBIX option is another possibility, though less ideal for automation or large‐scale governance.

     

    Best regards,