Performance Analyzer Archive | THE SELF-SERVICE-BI BLOG Wir lieben Microsoft Power BI Thu, 10 Apr 2025 11:43:56 +0000 de hourly 1 https://wordpress.org/?v=6.8.1 https://ssbi-blog.de/wp-content/uploads/2019/10/Favicon-150x150.png Performance Analyzer Archive | THE SELF-SERVICE-BI BLOG 32 32 How to identify Measures not used in your pbix file https://ssbi-blog.de/blog/technical-topics-english/how-to-identify-measures-not-used-in-your-pbix-file/ https://ssbi-blog.de/blog/technical-topics-english/how-to-identify-measures-not-used-in-your-pbix-file/#comments Tue, 09 Jul 2019 09:04:32 +0000 https://ssbi-blog.de/?p=5589 WARINING: Due to a broken DMV in Power BI Desktop, that I use for this solution, we cannot use this tool anymore, until until Microsoft fixes the issue. Sorry 😐 When I work with customers‘ pbix files, I often deal with files with several hundred measures. At the beginning I like to get an overview […]

Der Beitrag How to identify Measures not used in your pbix file erschien zuerst auf THE SELF-SERVICE-BI BLOG.

]]>
WARINING: Due to a broken DMV in Power BI Desktop, that I use for this solution, we cannot use this tool anymore, until until Microsoft fixes the issue. Sorry 😐

When I work with customers‘ pbix files, I often deal with files with several hundred measures. At the beginning I like to get an overview which of these measures might not be used at all and could possibly be removed. For this purpose, I have developed a method to locate these measures, which I would like to share in this article. Warning: Please note that this method does not consider the measures used in the Filter Pane! So before you delete a seemingly unused measure, please check if it was used in the Pane filter. 

You can download my report file at the end of this post. The download does not require a password. If you are still asked for your OneDrive password, change your browser to Edge.

The definition of unused measures

Unused Measures are Measures that are neither used in any visualization in the .pbix file nor referenced in other Measures, calculated columns or calculated tables! So how can I identify those Measures? Let’s find the answer together…

Gather the necessary information

To find the unused measures, I need the following information:

  • A list of all existing measures in the .pbix file,
  • A list of the measures used in the visualizations within the .pbix file
  • A list of measures referenced by other measures, calculated columns and/or calculated tables.

The logic is the following: When I remove from the all measures list those measures that are used in visualizations, I have those measures that are not used in visualizations. But they can still be referenced in other calculations (and therefore cannot be removed). So, if I hold against the list of all referencing calculations here, I finally get the measures that are not used within the .pbix file.

Retrieve a list of all measures

Since Power BI Desktop runs an instance of SQL Server Analysis Services Tabular in the background, I can use a DMV (Data Management View) to get information about my data model. You can use Power Query to gather this information using the following single line of code:

= OleDb.Query("Provider=MSOLAP.8;Data Source=localhost:61200;Update Isolation Level=2", "SELECT * FROM $SYSTEM.MDSCHEMA_MEASURES")

The result looks like this:

Using the DMV SYSTEM.MDSCHEMA_MEASURES to get information about all measures, Power BI, Power Query
Using the DMV SYSTEM.MDSCHEMA_MEASURES to get information about all measures

Be aware, that the number 61200 has to be changed in your code, as this is the process ID of the instance of Analysis Services running on your machine. The easiest way to find this number on your machine is to run DAX Studio (download it here) and connect it to your (already opened) pbix file. When you are connected, you find the desired process number in the bottom line, as you can see here:

finding the process ID of your Analysis Services instance behind Power BI Desktop
finding the process ID of your Analysis Services instance behind Power BI Desktop

Now that we have a list of all measures, let’s find those measures, that are used in report pages.

Retrieve a list of Measures, used in report pages in Power BI Desktop

Since May 2019 Power BI Desktop has been equipped with the extremely useful „Performance Analyzer„. This tool helps to find starting points for the optimization of slow reports. But this tool also helps me to identify those measures that are actually used on report pages. Follow these steps:

  1. Create a blank page
  2. Go to ViewPerformance Analzer and make the pane visible
  3. Click on Start recording
  4. Then select each page, one after another and wait until the visuals are fully loaded
  5. Press Stop
  6. Export the JSON file
Use the Performance Analyzer, to extract DAX queries from your pbix file, Power BI Desktop
Use the Performance Analyzer, to extract DAX queries from your pbix file

The JSON file contains all DAX queries, generated to update the visuals when selecting the page. If a measure is used in a visual, it is represented in the DAX query and I can extract that information from the JSON file. Of course I use Power Query to do that job for me and the result looks like this:

List of all measures, used in at least one visualization in the pbix file, Power BI Desktop
List of all measures, used in at least one visualization in the pbix file

Intermediate result

With the retrieval of all measures and the JSON file, with all measures used in visuals, I can now make a comparison and determine which measures are not used in visuals. So far, so good. However, just because a measure is not used directly in a visual, it is not automatically unused. It can be referenced in other measures, calculated columns, or calculated tables. Therefore I would like to check whether these now determined measures are really completely unused before I decide how I want to proceed with them…

Retrieve a list of calculation dependencies

The DMV, which I used for the retrieval of all existing measures, is by far not the only one available. Another useful DMV I will use to determine the measures referenced by other measures, calculated columns, or calculated tables is the following: $SYSTEM.discover_calc_dependency (see documentation of this DMV here).

I can again use Power Query to retrieve the results of this DMV like so:

= OleDb.Query("Provider=MSOLAP.8;Data Source=localhost:61200;Update Isolation Level=2", "SELECT * FROM $SYSTEM.discover_calc_dependency")

Again, the process id 61200 has to be changed to find the Analysis Services instance on your machine.

The result looks like this:

Using the DMV SYSTEM.MDSCHEMA_MEASURES to get information about all measures, Power BI Desktop, Power Query
Using the DMV SYSTEM.discover_calc_dependency to get information about calculation dependencies

This DMV returns a clear picture of the interdependencies of calculations. For me this DMV answers the question in which measures, calculated columns and/or calculated tables my measure is referenced. If a measure is not used in any visualization and does not appear in the calculation dependencies, it is unused.

The final table

With all this information, I can now create the following table, which tells me whether a measure is used in report pages and whether it is referenced in any way:

The final query: Which measure is not used at all in the pbix file, Power BI Desktop, Power Query
The final query: Which measure is not used at all in the pbix file

The screenshot shows in line 5 that the measure _Distinct_Medals is not used in visuals, but is at least referenced by other measures, calculated columns and/or tables. The measure „Not_used_anywhere“ is neither referenced nor used in visuals.

Download and usage of my Measure Analysis pbix file

I loaded all the described data from DMVs and the JSON export file into a pbix file and added a (very small, but helpful) report. Admittedly, I didn’t take any trouble with the optical design. I’ll leave that to you 😉

You can download the report file here.

Open the file and edit two parameters:

  • the process ID of the Analysis Services instance
  • the path and name of the exported JSON file (Make sure that your string does not contain quotation marks at the beginning and at the end)
Edit parameters, Power BI Desktop
Edit parameters
Enter new parameters, Power BI Desktop, Power Query
Enter new parameters

After you have clicked OK, you will see the following message in the upper part of the report page:

Click on „Apply changes“ and click on „Run“ in the following dialog, to allow the run of the DMV MDSCHEMA_MEASURES:

Run DMV MDSCHEMA_MEASURES, Power BI Desktop
Run DMV MDSCHEMA_MEASURES

Then you will be asked to enter your credentials. Use „Windows“ and „Use my current credentials“:

Use Windows credentials to connect to the instance of Analysis Services, Power BI Desktop
Use Windows credentials to connect to the instance of Analysis Services

After you have entered your credentials, Power Query prompts you to determine the privacy levels for the data source. Since in this particular case the communication between this PBIX file and the Analysis Services instance is behind the file to be analyzed, you can safely click on „Ignore Privacy Levels…“:

Ignore Privacy Levels and connect to pbix file, Power BI Desktop
Ignore Privacy Levels and connect to pbix file

Click on „Apply changes“ and click on „Run“ in the following dialog, to allow the run of the DMV :

Run DMV dicover_calc_dependency, Power BI Desktop
Run DMV dicover_calc_dependency

After the model refreshed, you can use the following report:

The final report: Find the unused meaures, Power BI Desktop, Power BI
The final report: Find the unused meaures

Here is a short description of the report:

  • Column1: Table name and Measure name.
  • Column2: If the measure was stored in a folder, you can read it here.
  • Column3: DAX-Expression of the measure
  • Column4: Is the measure used in a visual, somewhere in this pbix file?
  • Column5: Is this measure referenced by any measure, calculated column/ table in this pbix file?

I hope that this manual will help you to bring even more order into your data models 🙂

Greetings from Germany,

Lars

Der Beitrag How to identify Measures not used in your pbix file erschien zuerst auf THE SELF-SERVICE-BI BLOG.

]]>
https://ssbi-blog.de/blog/technical-topics-english/how-to-identify-measures-not-used-in-your-pbix-file/feed/ 44