Skip to main content

Optimising the Measures with DAX Studio

Another week another blog!! This week we will be focusing on the optimising the bad performing measures and how to tackle the measures generating Call back ID. Before starting, this blog is intended for Users who are a bit familiar with DAX Studio if not then you can do a quick read on our most read blog on our website (link).

Performance of report is a great factor in improving in the user experience and to check how well your visuals and DAX formulas are performing you can utilise the benefits of Performance Analyser. In my experience Performance analyser along with the DAX Studio is a match made in heaven. You can copy the query from Performance analyser and evaluate in DAX Studio. To know more about how performance analyser works do visit this interesting article (link).

Let's get our hands dirty and see how you can evaluate your DAX formulas. To do so I have created a basic DAX with help of Filter function 


Now, we have included this measure in a table along with the year coming from date table. Also, we have started recording with the help of Performance Analyser. Since our table is taking the most time to render let's evaluate the query running behind our DAX.


To do so you can copy query and go to DAX Studio with the connection to the same PBIX. Once you paste the copied query enable the server timings and query plan from top.


Now run the copied query and go to the server timings. What the heck is going on here? FE? SE? If you are not a fan of acronyms like me then FE stands for Formula engine while the SE stands for Storage Engine.


What does the FE and SE do? Here I would like to quote Data Mozart aka Nikola. Here is the link to the detailed article focusing on the concepts of SE and FE.


When you send the query to get data for your Power BI report, here is what happens:

  • Formula Engine (FE) accepts the request, process it, generates the query plan and finally executes it
  • Storage Engine (SE) pulls the data out of Tabular model to satisfy the request issued within the query generated by the Formula Engine
In simpler language FE act as a first layer and execute the DAX query as a rule of thumb do keep an eye on the number of queries generated in both Formula engine (FE) and Storage engine (SE). In this case, we have 3 queries running in background for this DAX. You can check the background query by clicking on every query. Now, let's optimise this by removing the Filter function in the DAX and repeat the same exercise. 

With a slight change in the DAX we have reduced the number of background queries also we have reduced the total duration from 17ms to 7ms. What has changed in the DAX?

Sales 100 filter = Calculate (Sum(Sales), 'Sales' > 100)

Isn't this amazing? Let's take it to the next level. On the journey of optimising the DAX you may encounter the concepts of Call Back ID. What is that? SE provides a data cache to FE but there are specific cases where the SE is unable to identify the DAX expression and ask the Call back ID to FE. 

Rule of thumb here states that try to get rid off the call back data ID because ultimately it slows down the performance of your DAX. The most common question here will be what are those DAX then can create Call back data ID. 

Perfect example for this will be use of IF function along with the iterators such as SUMX, AVGX and many more functions with X as a suffix to them. We have a created a measure with the same and we will see how call back data IDs are generated with just 3-4 lines of measures.


Once we have copied the query with the help of Performance analyser we will check the server timings and query plans running in background. 

To identify the queries that are generating the call back data ID once you check all the queries the one having the call back data ID it should be highlighted like mentioned in the image above. Also, note the total duration and the number of queries running in the background.

To improve this and as a part of best practices in optimising the DAX try not to combine the IF and iterator functions together instead use variables which can the eliminate the call back data ID. 



"All our articles are intended to address all the frequently asked questions related to a topic. Do leave a comment if it answers any of your question. "


Thanks for Reading Let's connect on LinkedIn. For more such blogs and pro tips do follow us





Comments

Post a Comment

Popular posts from this blog

Ultimate Beginners Guide to DAX Studio

There are zillions of external tools available with Power BI but DAX Studio is one of the most commonly used tools to work with DAX queries. It is a perfect tool to optimize the DAX and the data model. In this blog let's shed some light on the basic functionalities that can take your report to the next level. ARE YOU READY?  To start you will need the latest version of the DAX Studio. You can download it from their website . Don't worry you don't have to pay for the license. Fortunately, DAX Studio is a free tool As a BI Developer, I am using DAX Studio regularly. Based on my experience I use it for several purposes but in this blog, I will highlight the most common ones. Extracting a dump of all the measures used in your PBIX. Why do we need to do this? It can be used for documentation purposes also sometimes we try to reuse the DAX and such a dump comes in handy in this scenario. How to achieve it? Open the DAX Studio it is located under the external tools once you open t

Append v/s Merge in Power BI

Let's discuss another problem of the week. As a Power BI user, there are times when you want to combine queries. What are the ways to do so? In most cases, you can attain it by using either append or merge and both serve different purposes. Let's understand what do these terms mean in Power BI and how they are functionally different from each other.  It is quite common to get data from various sources and you need to combine those data depending on a particular column which is common in both tables so that you can add extra information or column to your big table. In such cases, we use merge queries. How to perform merge queries? For instance, I am considering Sample Superstore data and we will merge the returns table to the order table. You will find both merge and append in the home tab in extreme right in the power query editor. ProTip - You will find two options when you click on the drop-down in merge which are merge queries and merge queries as new. When you use merge que

Use Relationship in DAX

Data modeling is an essential part of creating perfect visuals. While creating complex data models there can be a case where you can find an inactive relationship represented by dotted lines and it occurs because you already have an active relationship between the two tables. But as a developer, you need to use both the relationship. How can it be done? You can use "Use Relationship" in such cases. Use relationship can be added to your DAX and act as a modifier or enhancer for calculation. It activates the inactive relation. But make sure you have an inactive relationship in place before using the use relationship function. Let's see how it works on Sample Superstore data. In my fact table I have two dates- Order date and Ship date. I am making the two relations between my date table and fact table. The relation between the sample superstore (date) to date table (date) is active while the relation between the sample superstore (ship date) to date table (date) is inactive