power-biapidax

Power BI: Retrieving Measure Definitions in the Semantic Model

INFO.MEASURES() requires a Premium licence. The Scan API doesn't — here's how to pull full DAX measure definitions without XMLA access.

December 11, 20242 min read

In a previous article, I discussed Usage Metrics Reports in Power BI. While exploring the usage metrics model, I noticed it contains some measures, but their definitions were not visible in Power BI Desktop.

I cannot see the measure definitions
I cannot see the measure definitions

Initially, I attempted to use the DAX query INFO.MEASURES() (DAX Guide) in the DAX editor. However, I encountered the following error:

The ‘XXXX’ user does not have permission to call the Discover method.

This happens because INFO.MEASURES() corresponds to the TMSCHEMA_MEASURES DMV (Data Management View), which requires access to XMLA endpoints. XMLA endpoints are available with at least a Power BI Premium license, while I currently have a Pro license.

The solution is to use the Scan API’s. With these API’s you can retrieve a lot of metadata of your models: the schema of the model, the data source, the lineage and even the DAX definition of measures:

(for datasetExpressions and datasetSchema you need to enable metadata scanning in the Power BI admin settings).

The Scan API works in three steps:

  1. Start the scan
  2. Check the scan status
  3. Retrieve the results

Start the scan

Use the following API call to start scanning the workspace that contains your usage metrics report:

curl --location 'https://api.powerbi.com/v1.0/myorg/admin/workspaces/getInfo?datasetExpressions=true&datasetSchema=true' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ••••••' \
--data '{
  "workspaces": [
    "XXXXX"
  ]
}'

Check the scan status

Once the scan starts, you’ll get an ID (let’s call it {pinkID}). Use this ID to check the status of the scan:

curl --location 'https://api.powerbi.com/v1.0/myorg/admin/workspaces/scanStatus/{pinkID}' \
--header 'Authorization: Bearer ••••••'

Retrieve the results

When the scan is complete, use the same {pinkID} to get the results:

curl --location 'https://api.powerbi.com/v1.0/myorg/admin/workspaces/scanResult/{pinkID}' \
--header 'Authorization: Bearer ••••••'

If you scroll down in the results, you’ll find the measure definitions:

As an example, we can see that the measure “P75 7d” is calculated as:

P-75 7d = 
CALCULATE(
    [P-25], 
    ALL(Dates), 
    DATESINPERIOD('Report load times'[Date], MAX('Report load times'[Date]), -7, DAY)
) + 0