The November 2022 version of Power BI Desktop shipped 3 new DAX functions, EVALUATEANDLOG, TOCSV and TOJSON. While the latter two may be of questionable value overall, the new EVALUATEANDLOG feature as explained here provides the potential to help more easily debug DAX. In a nutshell, EVALULATEANDLOG logs information that can be viewed using a SQL Server Profiler trace. This article explains how to do that in detail as well as how to easily configure SQL Server Profiler as an external tool for Power BI Desktop for even greater convenience.
First Things First
The first thing that you will need is to install SQL Server Management Studio (SSMS) from this link. The installation of SSMS includes the installation of the SQL Profiler tool, PROFILER.EXE. Once installed, launch SSMS. Make sure that you also have your Power BI Desktop file open. Once SSMS launches, you will be presented with a Connect to Server dialog as shown below:
For Server type, choose Analysis Services. Also choose Windows Authentication for the Authentication. For the Server name, in this case localhost:54256 there are a number of ways to identify the Analysis Services server used by the current Power BI Desktop application. One of the easiest is if you have any of my MSHGQM tools installed or any of the tools I created for Enterprise DNA. Simply launch one of these tools, such as Quick Measures Pro and in the upper-left of the screen the current server and database are identified as shown below:
The Data Source identifies the server while the Initial Catalog identifies the database or tabular cube. You can simply use your mouse to select the text after the first equals (=) sign up until the first semi-colon (;) and use Ctrl-C and then Ctrl-V to copy and paste this information into the Server name field.
Now click the Connect button. Within the Object Explorer, expand Databases and find the database corresponding to the Initial Catalog as shown below:
Select this database and then choose Tools | SQL Server Profiler from the menu as shown in the following image:
Your First Trace
SQL Profiler will launch and ask for connection information once again. You should be able to simply click the Connect button as the connection information will be the same as the most recently entered information for SSMS. Once connected, a Trace Properties dialog appears as shown below:
Click on the Events Selection tab at the top. On the Events Selection tab, check the box for Show all events and then under Query Processing find and check the box for DAX Evaluation Log as shown in the following image:
Now simply click the Run button and you have initialized your first trace for the DAX Evaluation Log!
Test it Out!
Switch to Power BI Desktop and create a simple measure like the following:
Measure 2 = EVALUATEANDLOG(SUM('Table'[Column2]))
Place this meausre into a visual and your trace should catch the data generated by EVALUATEANDLOG. You can force a refresh of any visuals on the page using the Performance analyzer pane and this will also be captured within the trace. Within the trace window in SQL Server Profiler, find the line corresponding to an EventClass of DAX Evaluation Log and select it to view the output of EVALUATEANDTRACE as shown below:
As shown in the image, the evaluation of the formula within the EVALUATEANDLOG function resulted in an output of 21.
Making it Easier
The use of SQL Server Profiler with Power BI Desktop can be made even easier and more seemless by configuring SQL Server Profiler as an external tool. This can be done by downloading SQLProfiler.pbitool.json from this site. The contents of the file are simply:
C:\Program Files (x86)\Common Files\Microsoft Shared\Power BI Desktop\External Tools
Now close and relaunch Power BI Desktop. SQL Server Profiler now appears as an external tool in the External Tools ribbon as shown below:
Clicking the SQL Profiler icon opens SQL Server Profiler and automatically creates a trace to the local tabular instance of Power BI Desktop. Stop the trace and then click on Properies using the icons highlighted in the image below:
As before, click on the Events Selection tab at the top. On the Events Selection tab, check the box for Show all events and then under Query Processing find and check the box for DAX Evaluation Log as shown in the following image:
Click the Run button.
The new EVALUATEANDLOG function is a useful addition that can help troubleshoot DAX calculations. With a bit of work, the SQL Server Profiler tool can be configured as an external tool for Power BI Desktop to make such troubleshooting quick, easy and largely seamless.