I am watching Jeffrey One as a live stream guest for Lead Havensand one of many dozen nice issues Jeffrey shared with viewers was the listing of optimizations the DAX engine performs when creating the perfect question plan for our actions.
And what caught my consideration was about what known as “sparse measures.”
To maintain it easy, we outlined the measure, Vertipaq’s formula engine Provides an implicit non-blank filter to the question. This permits the optimizer to keep away from an entire cross-connection of the dimension desk and scan solely rows the place data of dimension attribute combos really exist. To these coming from the MDX world, non-empty options could appear acquainted, however let’s check out how they work in Dax.
Essentially the most resonating with me was when Jeffrey suggested to interchange blanks with zeros (or specific values) in his energy BI calculations. I’ve already written it How to deal with white spaces and replace them with zerosnonetheless, on this article, we want to deal with the potential affect of this resolution on efficiency.
Set the stage
Earlier than you start, one vital disclaimer: the advice to not exchange white areas with zeros is strictly that. Really helpful. If a enterprise request reveals 0 as a substitute of clean, it doesn’t essentially imply that you need to reject it. In most situations you in all probability will not discover any efficiency degradation, however it depends upon a number of various factors…
First, let’s create a easy DAX measure.
Gross sales Amt 364 Merchandise =
CALCULATE (
[Sales Amt],
FILTER ( ALL ( 'Product'[ProductKey] ), 'Product'[ProductKey] = 364 )
)
Utilizing this scale, I want to calculate the overall gross sales quantity of a product utilizing ProductKey = 364. Put this measurement within the card visible, activate the Efficiency Analyzer and verify the processing time for this question, and you’re going to get the next outcomes:

The DAX question solely took 11 milliseconds to run. Switching to DaxStudio, the XMSQ generated by the method engine was quite simple.

Additionally, trying on the question plan (bodily) we will see that the storage engine solely discovered a mixture of current current combos to return information.

Including substances…
Nonetheless, as an instance what you are promoting request is to investigate the information in your product key 364 at a day by day stage. Go and add a date to the report.

This was additionally very quick! Test the metrics in Dax Studio.

This time the question was expanded to incorporate a desk of dates. This affected the working storage engine as a result of the numbers have been totally different this time as a substitute of discovering just one column.

After all, the distinction is only some milliseconds, so you will not discover the efficiency distinction between these two situations.
However that is only the start. We’re warming up the Dax engine. In each of those instances, as you possibly can see, solely row combos the place each of our necessities are met will solely present “met” values - the product secret is 364, and for those who look completely on the diagram above, there aren’t any consecutive dates, corresponding to January twelfth, January 14th to January twenty first, and a few have been neglected.
It’s because Method Engine was good sufficient to eradicate dates the place Product 364 was not promoting gross sales utilizing non-empty filters. Subsequently, the variety of data is 58.

Now as an instance enterprise customers need to see these dates whereas the product 364 was not on sale. So the concept is to show an quantity of $0 on all these dates. As already defined within the earlier article, there are a number of other ways to interchange blanks with zeros. COALESCE() operate:
Gross sales Amt 364 Merchandise with 0 = COALESCE([Sales Amt 364 Products],0)
basically, COALESCE The operate checks all of the arguments supplied (in my case there is just one argument) and replaces the primary clean worth with the desired worth. Merely put, verify if the worth of the AMT 364 merchandise bought is clean. In any other case, the calculated worth might be displayed. In any other case, exchange the clean with zero.

Wait, what? Once you filter all the things besides product 364, why do you see all the merchandise? For sure, my desk took me over 2 seconds to render! Let’s examine what occurred within the background.

As a substitute of producing one question, there are three queries: The primary one is strictly the identical because the earlier case (line 58). Nonetheless, the remainder of the queries goal the product and the date desk, pulling all rows from each tables (the product desk has 2517 rows and the date desk has 1826). Not solely that, but additionally check out our question plan.

4.6 million data? ! Why does that occur? ! Let me do math for you: 2.517 * 1.826 = 4.596.042…So, right here we’ve an entire cross be part of between the product desk and the date desk, forcing all tuples (date product combos)! It occurred as a result of I pressured the engine to return to 0 for all tuples that in any other case return to clean (and are then excluded from the scan consequently)!
This can be a easy overview of what occurred.

Imagine it or not, there’s a chic resolution that shows clean values straight away (however not 0 as a substitute of clean areas). Click on on the date subject and Shows gadgets with no information:

This additionally reveals clean cells, however with out performing a full cross be part of between the product and date desk:

Now we will see all of the cells (even blanks) and this question takes half the time of the earlier cell! Let’s take a look at the question plans generated by the method engine.

Not all situations are devastating!
The reality is, we may have rewritten the steps to rule out pointless data, however it could not be the easiest way for the engine to eradicate empty data.
Moreover, there are specific situations the place changing blanks with zeros doesn’t considerably cut back efficiency.
Let’s look into the next state of affairs: Shows information on complete gross sales for all manufacturers. And I will add a measure of the gross sales worth of product 364:

As you possibly can think about, it was very quick. However what occurs once you add a scale that replaces blanks with zeros?

It seems that HM didn’t should pay a penalty when it comes to efficiency. Let’s verify the question plan for this DAX question.

Conclusion
As Jeffrey Wang urged, it’s good to go away the blanks away from changing zeros (or different specific values). Nonetheless, if for some motive it’s good to exchange the blanks with some significant worth, watch out when and easy methods to do it.
As at all times, it depends upon many various facets – for those who do not show information from low cardinality columns, or for those who do not show information from a number of totally different tables (as in our instance, it’s good to mix information from a product and date desk), or for those who needn’t show many various values (i.e. visible visible) – you possibly can go away with out paying efficiency costs. However, for those who use a desk/matrix/bar chart that reveals many various values, verify the metrics and question plans earlier than deploying the report back to your manufacturing surroundings.
Thanks for studying!

